﻿using APICommond;
using BusinessEntity;
using BusinessEntity.Assets;
using BusinessEntity.CGGL;
using BusinessEntity.HT;
using BusinessEntity.HTGLQueery;
using BusinessEntity.HTGLQuerry;
using BusinessEntity.QuerryEntity;
using BusinessEntity.Warning;
using BusinessRepository;
using BusinessRule.Organization;
using NLog;
using NPOI.OpenXmlFormats.Dml;
using Org.BouncyCastle.Crypto;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics.Tracing;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace BusinessRule.HTGL
{
    public class HT_HTGL
    {
        #region "合同类型"
        public static async Task<(DataTable, int)> GetHT_HTLX(HT_HTLXQuerry querry)
        {
            string str = "  1=1 ";
            if (!string.IsNullOrEmpty(querry.htlxmc) && querry.htlxmc != "string")
            {
                str += "and htlxmc='" + querry.htlxmc + "'";
            }
            if (!string.IsNullOrEmpty(querry.lx) && querry.lx != "string")
            {
                str += " and lx='" + querry.lx + "'";
            }

            string sql = @"select listid,htlxbh,htlxmc,lx,zt from ht_htlxgl where " + str;
            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);

        }

        public static async Task InsertHT_HTLX(HT_HTLX ht)
        {
            string sql = "insert into ht_htlxgl (htlxbh,htlxmc,lx,zt) values ('" + ht.htlxbh + "','" + ht.htlxmc + "','" + ht.lx + "','启用'); ";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }

        public static async Task UpdateHT_HTLX(HT_HTLX ht)
        {
            string sql = "update ht_htlxgl set htlxmc='" + ht.htlxmc + "',lx='" + ht.lx + "' where htlxbh='" + ht.htlxbh + "'; ";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }

        public static async Task DeleteHT_HTLX(HT_HTLX ht)
        {
            string sql = "delete ht_htlxgl where htlxbh='" + ht.htlxbh + "'; ";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }

        public static async Task StopHT_HTLX(HT_HTLX ht)
        {
            string sql = "update ht_htlxgl set zt='停用' where htlxbh='" + ht.htlxbh + "'; ";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }

        public static async Task StartHT_HTLX(HT_HTLX ht)
        {
            string sql = "update ht_htlxgl set zt='启用' where htlxbh='" + ht.htlxbh + "'; ";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }
        #endregion

        #region"测绘"
        public static async Task<DataTable> GetHT_Detail(string htbh,string htlx)
        {
            string sql = "";

         
            if (htlx == "采购合同")
            {
                sql = "select * from HT_CGHT where htbh='" + htbh + "' ;";
            }
            if (htlx == "项目合同")
            {
                sql = "select * from ht_xmht where htbh='" + htbh + "' ;";
            }
            if (htlx == "通用付款合同")
            {
                sql = "select * from ht_tyfkht where htbh='" + htbh + "' ;";
            }
            if (htlx == "租赁合同")
            {
                sql = "select * from HT_ZLHT where htbh='" + htbh + "'  ;";

            }

            if (htlx == "通用收款合同")
            {
                sql = "select * from ht_tyskht where htbh='" + htbh + "' ;";
            }
            if (htlx == "产交合同")
            {
                sql = "select * from vw_ht_assets where xmbh='" + htbh + "' ; ";

            }


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        #endregion
        
        #region "付款合同管理"
        public static async Task<(IEnumerable<dynamic>, int)> GetHT_FKHTGL(HT_FKHTGLQuerry querry)
        {
            string str = "and   1=1 ";
            if (!string.IsNullOrEmpty(querry.htbh) && querry.htbh != "string")
            {
                str += "and htbh like '%" + querry.htbh + "%'";
            }
            if (!string.IsNullOrEmpty(querry.bmdm) && querry.bmdm != "string")
            {
                str += " and bmdm='" + querry.bmdm + "'";
            }
            if (!string.IsNullOrEmpty(querry.htmc) && querry.htmc != "string")
            {
                str += " and htmc like '%" + querry.htmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.htlx) && querry.htlx != "string")
            {
                str += " and htlx='" + querry.htlx + "'";
            }
            if (!string.IsNullOrEmpty(querry.zt) && querry.zt != "string")
            {
                str += " and zt='" + querry.zt + "'";
            }
            if (!string.IsNullOrEmpty(querry.jfmc) && querry.jfmc != "string")
            {
                str += " and jfmc like '%" + querry.jfmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.htzt) && querry.htzt != "string")
            {
                str += " and htzt= '" + querry.htzt + "'";
            }
            if (querry.sqksrq != null && querry.sqjsrq != null)
            {
                if (querry.sqjsrq > querry.sqksrq)
                {
                    DateTime sqjsrq = Convert.ToDateTime(querry.sqjsrq);
                    string jsrq = sqjsrq.ToString("yyyyMMdd");
                    DateTime sqksrq = Convert.ToDateTime(querry.sqksrq);
                    string ksrq = sqksrq.ToString("yyyyMMdd");
                    str += " and (sqrq>='" + ksrq + "' and sqrq<='" + jsrq + "')";
                }
            }

            string sql = @"select * from vw_ht_fkhtgl where (bmdm in " + querry.DepartID + " or htbh in (select distinct htbh from HT_htzxbm where deptid in " + querry.DepartID + "))"+ str ;
            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            //return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.PageSize, querry.Current);
            return await new RepositoryFactory().BaseRepository().FindList(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);
        }
        public static async Task<DataTable> DeleteHT_FKHT(HT_FKHTXX ht)
        {

            string sql = "";
            if (ht.htlx == "采购合同")
            {
                sql = "delete HT_CGHT  where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "delete HT_BDWXX  where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "delete ht_skzh where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "delete ht_fkjh where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "delete ht_bzj where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "delete ht_yfxx where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }
            if (ht.htlx == "项目合同")
            {
                sql = "delete ht_xmht  where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "delete ht_skzh  where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "delete ht_fkjh where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "delete ht_bzj where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "delete ht_yfxx where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }
            if (ht.htlx == "通用付款合同")
            {
                sql = "delete  ht_tyfkht  where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "delete HT_BDWXX  where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "delete ht_skzh  where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "delete ht_fkjh  where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "delete ht_bzj  where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "delete ht_yfxx where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        //作废
        public static async Task<DataTable> StopHT_FKHT(HT_FKHTXX ht)
        {

            string sql = "";
            if (ht.htlx == "采购合同")
            {
                sql = "update HT_CGHT set zt='5' where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "update HT_BDWXX set zt='5' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_skzh set zt='5' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_fkjh set zt='5' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_bzj set zt='5' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_yfxx set zt='5' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }
            if (ht.htlx == "项目合同")
            {
                sql = "update ht_xmht set zt='5' where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "update ht_skzh set zt='5' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_fkjh set zt='5' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_bzj set zt='5' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_yfxx set zt='5' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }
            if (ht.htlx == "通用付款合同")
            {
                sql = "update  ht_tyfkht set zt='5' where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "update HT_BDWXX set zt='5' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_skzh set zt='5' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_fkjh set zt='5' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_bzj set zt='5' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_yfxx set zt='5' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> SubmitHT_FKHT(HT_FKHTXX ht)
        {

            string sql = "";
            if (ht.htlx == "采购合同")
            {
                sql = "update HT_CGHT set zt='2' where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "update HT_BDWXX set zt='2' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_skzh set zt='2' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_fkjh set zt='2' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_bzj set zt='2' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_yfxx set zt='2' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }
            if (ht.htlx == "项目合同")
            {
                sql = "update ht_xmht set zt='2' where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "update ht_skzh set zt='2' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_fkjh set zt='2' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_bzj set zt='2' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_yfxx set zt='2' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }
            if (ht.htlx == "通用付款合同")
            {
                sql = "update  ht_tyfkht set zt='2' where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "update HT_BDWXX set zt='2' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_skzh set zt='2' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_fkjh set zt='2' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_bzj set zt='2' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_yfxx set zt='2' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> AuditHT_FKHT(HT_FKHTXX ht)
        {

            string sql = "";
            if (ht.htlx == "采购合同")
            {
                sql = "update HT_CGHT set zt='3' where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "update HT_BDWXX set zt='3' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_skzh set zt='3' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_fkjh set zt='3' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_bzj set zt='3' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_yfxx set zt='3' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }
            if (ht.htlx == "项目合同")
            {
                sql = "update ht_xmht set zt='3' where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "update ht_skzh set zt='3' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_fkjh set zt='3' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_bzj set zt='3' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_yfxx set zt='3' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }
            if (ht.htlx == "通用付款合同")
            {
                sql = "update  ht_tyfkht set zt='3' where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "update HT_BDWXX set zt='3' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_skzh set zt='3' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_fkjh set zt='3' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_bzj set zt='3' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_yfxx set zt='3' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> BackHT_FKHT(HT_FKHTXX ht)
        {

            string sql = "";
            if (ht.htlx == "采购合同")
            {
                sql = "update HT_CGHT set zt='4' where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "update HT_BDWXX set zt='4' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_skzh set zt='4' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_fkjh set zt='4' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_bzj set zt='4' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_yfxx set zt='4' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }
            if (ht.htlx == "项目合同")
            {
                sql = "update ht_xmht set zt='4' where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "update ht_skzh set zt='4' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_fkjh set zt='4' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_bzj set zt='4' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_yfxx set zt='4' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }
            if (ht.htlx == "通用付款合同")
            {
                sql = "update  ht_tyfkht set zt='4' where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "update HT_BDWXX set zt='4' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_skzh set zt='4' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_fkjh set zt='4' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_bzj set zt='4' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_yfxx set zt='4' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> UpdateHT_HTZT(string htbh,string htlx,string zt)
        {

            string sql = "";
            if (htlx == "采购合同")
            {
                sql = "update HT_CGHT set zt='"+zt+"' where htbh='" + htbh + "' ;  ";
                sql += "update HT_BDWXX set zt='" + zt + "' where htbh='" + htbh + "' ; ";
                sql += "update ht_skzh set zt='" + zt + "' where htbh='" + htbh + "' ; ";
                sql += "update ht_fkjh set zt='" + zt + "' where htbh='" + htbh + "' ; ";
                sql += "update ht_bzj set zt='" + zt + "' where htbh='" + htbh + "' ; ";
                sql += "update ht_yfxx set zt='" + zt + "' where htbh='" + htbh + "' ; ";
            }
            if (htlx == "项目合同")
            {
                sql = "update ht_xmht set zt='"+zt+"' where htbh='" + htbh + "';  ";
                sql += "update ht_skzh set zt='" + zt + "' where htbh='" + htbh + "' ; ";
                sql += "update ht_fkjh set zt='" + zt + "' where htbh='" + htbh + "';  ";
                sql += "update ht_bzj set zt='" + zt + "' where htbh='" + htbh + "' ; ";
                sql += "update ht_yfxx set zt='" + zt + "' where htbh='" + htbh + "'; ";
            }
            if (htlx == "通用付款合同")
            {
                sql = "update  ht_tyfkht set zt='"+zt+"' where htbh='" + htbh + "';  ";
                sql += "update HT_BDWXX set zt='" + zt + "' where htbh='" + htbh + "' ; ";
                sql += "update ht_skzh set zt='" + zt + "' where htbh='" + htbh + "' ; ";
                sql += "update ht_fkjh set zt='" + zt + "' where htbh='" + htbh + "' ; ";
                sql += "update ht_bzj set zt='" + zt + "' where htbh='" + htbh + "' ; ";
                sql += "update ht_yfxx set zt='" + zt + "' where htbh='" + htbh + "' ; ";
            }
            if (htlx == "租赁合同")
            {
                sql = "update HT_ZLHT set zt='"+zt+"' where htbh='" + htbh + "' ; ";
                sql += "update HT_zcxx set zt='" + zt + "' where htbh='" + htbh + "' ; ";
                sql += "update HT_ZLHT_bdzj set zt='" + zt + "' where htbh='" + htbh + "'; ";
                sql += "update ht_skjh set zt='" + zt + "' where htbh='" + htbh + "' ; ";
                sql += "update ht_bzj set zt='" + zt + "' where htbh='" + htbh + "'; ";

            }

            if (htlx == "通用收款合同")
            {
                sql = "update  ht_tyskht set zt='"+zt+"' where htbh='" + htbh + "'  ; ";
                sql += "update HT_BDWXX set zt='" + zt + "' where htbh='" + htbh + "'; ";

                sql += "update ht_skjh set zt='" + zt + "' where htbh='" + htbh + "' ; ";
                sql += "update ht_bzj set zt='" + zt + "' where htbh='" + htbh + "' ;  ";
                sql += "update ht_yfxx set zt='" + zt + "' where htbh='" + htbh + "' ;  ";
            }
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> SubmitHT(string htbh,string htlx)
        {

            string sql = "";
            if (htlx == "采购合同")
            {
                sql = "update HT_CGHT set zt='2' where htbh='" + htbh + "' ; ";
                sql += "update HT_BDWXX set zt='2' where htbh='" + htbh + "' ; ";
                sql += "update ht_skzh set zt='2' where htbh='" + htbh + "' ; ";
                sql += "update ht_fkjh set zt='2' where htbh='" + htbh + "' ; ";
                sql += "update ht_bzj set zt='2' where htbh='" + htbh + "' ; ";
                sql += "update ht_yfxx set zt='2' where htbh='" + htbh + "' ; ";
            }
            if (htlx == "项目合同")
            {
                sql = "update ht_xmht set zt='2' where htbh='" + htbh + "' ;";
                sql += "update ht_skzh set zt='2' where htbh='" + htbh + "' ; ";
                sql += "update ht_fkjh set zt='2' where htbh='" + htbh + "' ; ";
                sql += "update ht_bzj set zt='2' where htbh='" + htbh + "' ; ";
                sql += "update ht_yfxx set zt='2' where htbh='" + htbh + "' ; ";
            }
            if (htlx == "通用付款合同")
            {
                sql = "update  ht_tyfkht set zt='2' where htbh='" + htbh + "' ;";
                sql += "update HT_BDWXX set zt='2' where htbh='" + htbh + "' ; ";
                sql += "update ht_skzh set zt='2' where htbh='" + htbh + "' ; ";
                sql += "update ht_fkjh set zt='2' where htbh='" + htbh + "' ; ";
                sql += "update ht_bzj set zt='2' where htbh='" + htbh + "' ; ";
                sql += "update ht_yfxx set zt='2' where htbh='" + htbh + "' ; ";
            }
            if (htlx == "租赁合同")
            {
                sql = "update HT_ZLHT set zt='2' where htbh='" + htbh + "' ';";
                sql += "update HT_ZLHT_JBXX set zt='2' where htbh='" + htbh + "'  ; ";
                sql += "update HT_ZLHT_bdzj set zt='2' where htbh='" + htbh + "' ; ";

                sql += "update ht_bzj set zt='2' where htbh='" + htbh + "' ; ";

            }

            if (htlx == "通用收款合同")
            {
                sql = "update  ht_tyskht set zt='2' where htbh='" + htbh + "' ;";
                sql += "update HT_BDWXX set zt='2' where htbh='" + htbh + "'  ; ";

                sql += "update ht_skjh set zt='2' where htbh='" + htbh + "'  ; ";
                sql += "update ht_bzj set zt='2' where htbh='" + htbh + "'  ; ";
                sql += "update ht_yfxx set zt='2' where htbh='" + htbh + "'  ; ";
            }
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        //状态  删除：0，未提交：1  未审核：2  审核通过：3 驳回：4 作废：5
        #endregion
        #region "获取付款合同信息"
        public static async Task<DataTable> GetHT_FKHTXX(string htbh, string htmc, string htlx, string zt)
        {
            string sql = "";
            if (htlx == "采购合同")
            {
                sql = "select * from HT_CGHT where htbh='" + htbh + "' and htmc='" + htmc + "' ;";
            }
            if (htlx == "项目合同")
            {
                sql = "select * from ht_xmht where htbh='" + htbh + "' and htmc='" + htmc + "';";
            }
            if (htlx == "通用付款合同")
            {
                sql = "select * from ht_tyfkht where htbh='" + htbh + "' and htmc='" + htmc + "';";
            }

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        #endregion

        #region "采购合同"
        public static async Task InsertHT_CGHT(HT_CGHT_Total ht)
        {
            HT_CGHT cght = ht.cght;
            if (cght.Listid == "")
            {
                string sql = @"delete from ht_cght where htbh='"+ cght.htbh+@"';insert into ht_cght ( sqr, sqbm, sqrq, jfmc, jffrdb, jfdbry, jflxdh, jffdzd, jfyb, jfshxydm, jfsfzhm,
               htmc, htbh, htqdrq, htje, htkssj, htjssj, jkfs, cfdd, htqddd, fkzytj, htgfzyyw, wyzr, qtsx, zt,bmdm,cgptbm,cgbdid )
            values ('" + cght.sqr + "','" + cght.sqbm + "','" + cght.sqrq + "','" + cght.jfmc + "','" + cght.jffrdb + "','" + cght.jfdbry + "','" + cght.jflxdh + "','" + cght.jffdzd + "','" + cght.jfyb +
            "','" + cght.jfshxydm + "','" + cght.jfsfzhm + "','" + cght.htmc + "','" + cght.htbh + "','" + cght.htqdrq + "','" + cght.htje + "','" + cght.htkssj + "','" + cght.htjssj + "','" + cght.jkfs + 
            "','" + cght.cfdd + "','" + cght.htqddd + "','" + cght.fkzytj + "','" + cght.htgfzyyw + "','" + cght.wyzr + "','" + cght.qtsx + "','"+cght.zt+"','"+cght.bmdm+"','"+cght.cgptbm + "','"+cght.cgbdid+"'); ";
                await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            }
            else
            {
                await UpdateHT_CGHT(cght);
            }
            await DeleteHT_BDWXX(cght.htbh);
            foreach (HT_BDWXX bdwxx in ht.bdwxx)
            {
                await InsertHT_BDWXX(bdwxx);
            }
            await DeleteHT_SKZH(cght.htbh);
            foreach (HT_SKZH skzh in ht.skzh)
            {
                await InsertHT_SKZH(skzh);
            }
            await DeleteHT_FKJH(cght.htbh);
            foreach (HT_FKJH fkjh in ht.fkjh)
            {
                await InsertHT_FKJH(fkjh);
            }
            await DeleteHT_BZJ(cght.htbh);
            foreach (HT_BZJ bzj in ht.bzj)
            {
                await InsertHT_BZJ(bzj);
            }
            await DeleteHT_YFXX(cght.htbh);
            foreach (HT_YFXX yfxx in ht.yfxx)
            {
                await InsertHT_YFXX(yfxx);
            }
            await DeleteHT_HTZXBM(cght.htbh);
            foreach (HT_Htzxbm htzxbm in ht.htzxbm)
            {
                await InsertHT_HTZXBM(htzxbm);
            }

        }
        public static async Task UpdateHT_CGHT(HT_CGHT ht)
        {
            string sql = @"update ht_cght set  sqr='" + ht.sqr + "',	 sqbm='" + ht.sqbm + "',	 sqrq='" + ht.sqrq + "',	 jfmc='" + ht.jfmc + "',	 jffrdb='" + ht.jffrdb + "',	 jfdbry='" + ht.jfdbry + "',	 jflxdh='" + ht.jflxdh + "',	 jffdzd='" + ht.jffdzd + "',	 jfyb='" + ht.jfyb + "',	" +
                " jfshxydm='" + ht.jfshxydm + "',	 jfsfzhm='" + ht.jfsfzhm + "', htqdrq='" + ht.htqdrq + "',	 htje='" + ht.htje + "',	 htkssj='" +
                ht.htkssj + "',	 htjssj='" + ht.htjssj + "',	 jkfs='" + ht.jkfs + "',	 cfdd='" + ht.cfdd + "',	 htqddd='" + ht.htqddd + "',	" +
                " fkzytj='" + ht.fkzytj + "',	 htgfzyyw='" + ht.htgfzyyw + "',	 wyzr='" + ht.wyzr + "',	 qtsx='" + ht.qtsx + "',htmc='" + ht.htmc + "' , zt='" + ht.zt + "',bmdm='"+ht.bmdm+ "',cgptbm='" + ht.cgptbm + "'  where 	  listid='" + ht.Listid + "' and htbh='"+ht.htbh+"' ; ";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }





        #endregion
        #region "项目合同"
        public static async Task InsertHT_XMHT(HT_XMHT_Total ht)
        {
            HT_XMHT xmht = ht.xmht;
            if (xmht.Listid == "")
            {
                string sql = @"insert into HT_XMHT (sqr, sqbm, sqrq, jfmc, jffrdb, jfdbry, jflxdh, jffdzd, jfyb, jfshxydm, jfsfzhm,  htmc, htbh, htqdrq, htje, htkssj, htjssj, jkfs, cfdd, htqddd, xmmc, bd, gspsje, kgrq, jgrq, yfk, xmjl, xmhtlx, zrqxq, fkzytj, htgfzyyw, wyzr, qtsx, zt,bmdm,zbcjdh)
values('" + xmht.sqr + "','" + xmht.sqbm + "','" + xmht.sqrq + "','" + xmht.jfmc + "','" + xmht.jffrdb + "','" + xmht.jfdbry + "','" + xmht.jflxdh + "','" + xmht.jffdzd + "','" + xmht.jfyb + "','" + xmht.jfshxydm + "','" + xmht.jfsfzhm + "','" + xmht.htmc + "','" + xmht.htbh + "','" + xmht.htqdrq + "','" + xmht.htje + "','" + xmht.htkssj + "','" + xmht.htjssj + "','" + xmht.jkfs + "','" + xmht.cfdd + "','" + xmht.htqddd + "','" + xmht.xmmc + "','" + xmht.bd + "','" + xmht.gspsje + "','" + xmht.kgrq + "','" + xmht.jgrq + "','" + xmht.yfk + "','" + xmht.xmjl + "','" + xmht.xmhtlx + "','" + xmht.zrqxq + "','" + xmht.fkzytj + "','" + xmht.htgfzyyw + "','" + xmht.wyzr + "','" + xmht.qtsx + "','1','"+xmht.bmdm+"','"+xmht.zbcjdh+"' );  ";

                await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            }
            else
            {
                await UpdateHT_XMHT(xmht);
            }
            await DeleteHT_SKZH(xmht.htbh);
            foreach (HT_SKZH skzh in ht.skzh)
            {
                await InsertHT_SKZH(skzh);

            }
            await DeleteHT_FKJH(xmht.htbh);
            foreach (HT_FKJH fkjh in ht.fkjh)
            {
                await InsertHT_FKJH(fkjh);

            }
            await DeleteHT_BZJ(xmht.htbh);
            foreach (HT_BZJ bzj in ht.bzj)
            {
                await InsertHT_BZJ(bzj);

            }
            await DeleteHT_YFXX(xmht.htbh);
            foreach (HT_YFXX yfxx in ht.yfxx)
            {
                await InsertHT_YFXX(yfxx);

            }
        }
        public static async Task UpdateHT_XMHT(HT_XMHT ht)
        {
            string sql = @"update ht_xmht set  sqr='" + ht.sqr + "', sqbm='" + ht.sqbm + "', sqrq='" + ht.sqrq + "', jfmc='" + ht.jfmc + "', jffrdb='" + ht.jffrdb + "', jfdbry='" + ht.jfdbry + "', jflxdh='" + ht.jflxdh + "', jffdzd='" + ht.jffdzd + "', jfyb='" + ht.jfyb + "', jfshxydm='" + ht.jfshxydm + "', jfsfzhm='" + ht.jfsfzhm + "', htqdrq='" + ht.htqdrq + "', htje='" + ht.htje + "', htkssj='" + ht.htkssj + "', htjssj='" + ht.htjssj + "', jkfs='" + ht.jkfs + "', cfdd='" + ht.cfdd + "', htqddd='" + ht.htqddd + "', xmmc='" + ht.xmmc + "',bd='" + ht.bd + "', gspsje='" + ht.gspsje + "',kgrq='" + ht.kgrq + "', jgrq='" + ht.jgrq + "', yfk='" + ht.yfk + "', xmjl='" + ht.xmjl + "', xmhtlx='" + ht.xmhtlx + "', zrqxq='" + ht.zrqxq + "', fkzytj='" + ht.fkzytj + "', htgfzyyw='" + ht.htgfzyyw + "', wyzr='" + ht.wyzr + "', qtsx='" + ht.qtsx + "', zt='" + ht.zt + "' , htmc='" + ht.htmc + "' ,zbcjdh='"+ht.zbcjdh+"',bmdm='"+ht.bmdm+"'  where listid='" + ht.Listid + "' and htbh='"+ht.htbh+"'	  ; ";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }





        #endregion
        #region "通用付款合同"
        public static async Task InsertHT_TYFKHT(HT_TYFKHT_Total ht)
        {
            HT_TYFKHT tyfkht = ht.tyfkht;
            if (tyfkht.Listid == "")
            {
                string sql = @"delete from HT_tyfkht where htbh='"+tyfkht.htbh+@"'; insert into HT_tyfkht (sqr, sqbm, sqrq, jfmc, jffrdb, jfdbry, jflxdh, jffdzd, jfyb, jfshxydm, jfsfzhm,  htmc, htbh, htqdrq, htje, htkssj, htjssj, jkfs, cfdd, htqddd, fkzytj, htgfzyyw, wyzr, qtsx, zt,bmdm,cgptbm)
values('" + tyfkht.sqr + "','" + tyfkht.sqbm + "','" + tyfkht.sqrq + "','" + tyfkht.jfmc + "','" + tyfkht.jffrdb + "','" + tyfkht.jfdbry + "','" + tyfkht.jflxdh + "','" + tyfkht.jffdzd + "','" + tyfkht.jfyb + "','" + tyfkht.jfshxydm + "','" + tyfkht.jfsfzhm + "','" + tyfkht.htmc + "','" + tyfkht.htbh + "','" + tyfkht.htqdrq + "','" + tyfkht.htje + "','" + tyfkht.htkssj + "','" + tyfkht.htjssj + "','" + tyfkht.jkfs + "','" + tyfkht.cfdd + "','" + tyfkht.htqddd + "','" + tyfkht.fkzytj + "','" + tyfkht.htgfzyyw + "','" + tyfkht.wyzr + "','" + tyfkht.qtsx + "','1','"+tyfkht.bmdm+"','"+tyfkht.cgptbm + "' );  ";
                await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            }
            else
            {
                await UpdateHT_TYFKHT(tyfkht);
            }
            await DeleteHT_BDWXX(tyfkht.htbh);
            foreach (HT_BDWXX bdwxx in ht.bdwxx)
            {
                await InsertHT_BDWXX(bdwxx);
            }
            await DeleteHT_SKZH(tyfkht.htbh);
            foreach (HT_SKZH skzh in ht.skzh)
            {
                await InsertHT_SKZH(skzh);
            }
            await DeleteHT_FKJH(tyfkht.htbh);
            foreach (HT_FKJH fkjh in ht.fkjh)
            {
                await InsertHT_FKJH(fkjh);
            }
            await DeleteHT_BZJ(tyfkht.htbh);
            foreach (HT_BZJ bzj in ht.bzj)
            {
                await InsertHT_BZJ(bzj);
            }
            await DeleteHT_YFXX(tyfkht.htbh);
            foreach (HT_YFXX yfxx in ht.yfxx)
            {
                await InsertHT_YFXX(yfxx);

            }
            await DeleteHT_HTZXBM(tyfkht.htbh);
            foreach (HT_Htzxbm htzxbm in ht.htzxbm)
            {
                await InsertHT_HTZXBM(htzxbm);
            }
        }
        public static async Task UpdateHT_TYFKHT(HT_TYFKHT ht)
        {
            string sql = @"update ht_tyfkht set sqr='" + ht.sqr + "', sqbm='" + ht.sqbm + "', sqrq='" + ht.sqrq + "', jfmc='" + ht.jfmc + "', jffrdb='" + ht.jffrdb + "', jfdbry='" + ht.jfdbry + "', jflxdh='" + ht.jflxdh + "', jffdzd='" + ht.jffdzd + "', jfyb='" + ht.jfyb + "', jfshxydm='" + ht.jfshxydm + "', jfsfzhm='" + ht.jfsfzhm + "',   htqdrq='" + ht.htqdrq + "', htje='" + ht.htje + "', htkssj='" + ht.htkssj + "', htjssj='" + ht.htjssj + "', jkfs='" + ht.jkfs + "', cfdd='" + ht.cfdd + "', htqddd='" + ht.htqddd + "', fkzytj='" + ht.fkzytj + "', htgfzyyw='" + ht.htgfzyyw + "', wyzr='" + ht.wyzr + "', qtsx='" + ht.qtsx + "',zt='" + ht.zt + "' , htmc='" + ht.htmc + "' , 	bmdm='"+ht.bmdm+ "',cgptbm='" + ht.cgptbm + "' where 	 listid='" + ht.Listid + "' and htbh='"+ht.htbh+"' and htbh='"+ht.htbh+"' ; ";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }





        #endregion

        #region "收款合同管理"
        public static async Task<(IEnumerable<dynamic>, int)> GetHT_SKHTGL(HT_SKHTGLQuerry querry)
        {
            string str = " and 1=1 ";
            if (!string.IsNullOrEmpty(querry.htbh) && querry.htbh != "string")
            {
                str += "and htbh like '%" + querry.htbh + "%'";
            }
            if (!string.IsNullOrEmpty(querry.htmc) && querry.htmc != "string")
            {
                str += " and htmc like '%" + querry.htmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.bmdm) && querry.bmdm != "string")
            {
                str += " and bmdm='" + querry.bmdm + "'";
            }
            if (!string.IsNullOrEmpty(querry.htlx) && querry.htlx != "string")
            {
                str += " and htlx='" + querry.htlx + "'";
            }
            if (!string.IsNullOrEmpty(querry.zt) && querry.zt != "string")
            {
                str += " and zt='" + querry.zt + "'";
            }
            if (!string.IsNullOrEmpty(querry.jfmc) && querry.jfmc != "string")
            {
                str += " and jfmc like '%" + querry.jfmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.htzt) && querry.htzt != "string")
            {
                str += " and htzt = '" + querry.htzt + "'";
            }
            if (querry.sqksrq != null && querry.sqjsrq != null)
            {
                if (querry.sqjsrq > querry.sqksrq)
                {
                    DateTime sqjsrq = Convert.ToDateTime(querry.sqjsrq);
                    string jsrq = sqjsrq.ToString("yyyyMMdd");
                    DateTime sqksrq = Convert.ToDateTime(querry.sqksrq);
                    string ksrq = sqksrq.ToString("yyyyMMdd");
                    str += " and (sqrq>='" + ksrq + "' and sqrq<='" + jsrq + "')";
                }
            }

            string sql = @"select * from vw_ht_skhtgl where (bmdm in " + querry.DepartID + " or htbh in (select distinct htbh from HT_htzxbm where deptid in " + querry.DepartID + "))" + str;
            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            // return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.PageSize, querry.Current);
            return await new RepositoryFactory().BaseRepository().FindList(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);

        }


        public static async Task<DataTable> GetHT_SKHTGLx(string[] htbh)
        {
            string str = "";
           
            foreach (string s in htbh)
            {
                str += "'" + s + "',";
            }
            str= str.Substring(0,str.Length-1)+"";
            string sql = @"select * from vw_ht_skhtgl where htbh in("+ str+")";
            bool isAsc = true;

            return await new RepositoryFactory().BaseRepository().FindTable(sql,null);

        }
        public static async Task<DataTable> DeleteHT_SKHT(HT_SKHTXX ht)
        {

            string sql = "";
            if (ht.htlx == "租赁合同")
            {
                sql = "delete HT_ZLHT  where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "delete HT_ZLHT_bdzj  where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "delete HT_ZLHT_JBXX  where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "delete ht_bzj  where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
               // sql += "delete ht_yfxx  where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }

            if (ht.htlx == "通用收款合同")
            {
                sql = "delete  ht_tyskht  where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "delete HT_BDWXX  where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";

                sql += "delete ht_skjh  where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "delete ht_bzj  where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "delete ht_yfxx  where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        //作废
        public static async Task<DataTable> StopHT_SKHT(HT_SKHTXX ht)
        {

            string sql = "";
            if (ht.htlx == "租赁合同")
            {
                sql = "update HT_ZLHT set zt='5' where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "update HT_ZLHT_bdzj set zt='5' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";

                sql += "update HT_ZLHT_JBXX set zt='5' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";

                sql += "update ht_bzj set zt='5' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
               // sql += "update ht_yfxx set zt='5' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }

            if (ht.htlx == "通用收款合同")
            {
                sql = "update  ht_tyskht set zt='5' where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "update HT_BDWXX set zt='5' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";

                sql += "update ht_skjh set zt='5' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_bzj set zt='5' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_yfxx set zt='5' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> SubmitHT_SKHT(HT_SKHTXX ht)
        {

            string sql = "";
            if (ht.htlx == "租赁合同")
            {
                sql = "update HT_ZLHT set zt='2' where htbh='" + ht.htbh + "' ;";
               
                
            }

            if (ht.htlx == "通用收款合同")
            {
                sql = "update  ht_tyskht set zt='2' where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "update HT_BDWXX set zt='2' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";

                sql += "update ht_skjh set zt='2' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_bzj set zt='2' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_yfxx set zt='2' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> AuditHT_SKHT(HT_SKHTXX ht)
        {

            string sql = "";
            if (ht.htlx == "租赁合同")
            {
                sql = "update HT_ZLHT set zt='3' where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "update HT_ZLHT_bdzj set zt='3' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";

                sql += "update HT_ZLHT_JBXX set zt='3' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";

                sql += "update ht_bzj set zt='3' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
               // sql += "update ht_yfxx set zt='3' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }

            if (ht.htlx == "通用收款合同")
            {
                sql = "update  ht_tyskht set zt='3' where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "update HT_BDWXX set zt='3' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";

                sql += "update ht_skjh set zt='3' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_bzj set zt='3' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_yfxx set zt='3' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> BackHT_SKHT(HT_SKHTXX ht)
        {

            string sql = "";
            if (ht.htlx == "租赁合同")
            {
                sql = "update HT_ZLHT set zt='4' where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "update HT_ZLHT_JBXX set zt='4' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; "; sql += "update HT_ZLHT_JBXX set zt='4' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update HT_ZLHT_bdzj set zt='4' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";

                sql += "update ht_bzj set zt='4' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
               // sql += "update ht_yfxx set zt='4' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }

            if (ht.htlx == "通用收款合同")
            {
                sql = "update  ht_tyskht set zt='4' where htbh='" + ht.htbh + "' and htmc='" + ht.htmc + "' and zt='" + ht.zt + "';";
                sql += "update HT_BDWXX set zt='4' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";

                sql += "update ht_skjh set zt='4' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_bzj set zt='4' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
                sql += "update ht_yfxx set zt='4' where htbh='" + ht.htbh + "' and zt='" + ht.zt + "'; ";
            }

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        #endregion
        #region "获取收款合同信息"
        public static async Task<DataTable> GetHT_SKHTXX(string htbh,string htlx)
        {
            string sql = "";
            if (htlx == "租赁合同")
            {
                sql = "select * from HT_ZLHT where htbh='" + htbh + "'  ;";
               
            }

            if (htlx == "通用收款合同")
            {
                sql = "select * from ht_tyskht where htbh='" + htbh + "' ;";
            }
            if (htlx == "产交合同")
            {
                sql = "select * from vw_ht_assets where xmbh='" + htbh + "' ; ";
               
            }
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        #endregion

        #region "产交合同补全"

        public static async Task UpdateContract(contract co)
        {
            string sql = "update contract set yhtbh='"+co.ht.yhtbh+ "',bz='"+co.ht.bz+ "',ywyf="+co.ht.ywyf+",yzj="+co.ht.yzj+",jylx='"+co.ht.jylx+
                "',htsm='"+co.ht.htsm+ "',zlmj="+co.ht.czmj+" where projcode='"+co.ht.xmbh+ "' and contractcode='"+co.ht.htbh+"'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            await DeleteHT_SKJH(co.ht.htbh);
            foreach (HT_SKJH skjh in co.skjh)
            {
                await InsertHT_SKJH(skjh);
            }
            await DeleteHT_BZJ(co.ht.htbh);
            foreach (HT_BZJ bzj in co.bzj)
            { 
                if (string.IsNullOrEmpty(bzj.htbh))
                {
                    bzj.htbh = co.ht.htbh;
                }
                    await InsertHT_BZJ(bzj);
            }
            await deleteht_srqrb(co.ht.htbh);
            foreach (ht_srqrb sr in co.srqrb)
            {
                if (string.IsNullOrEmpty(sr.htbh))
                {
                    sr.htbh = co.ht.htbh;
                }
                await insertht_srqrb(sr);
            }
            foreach (ht_yys yys in co.yys)
            {
                if (string.IsNullOrEmpty(yys.htbh))
                {
                    yys.htbh = co.ht.htbh;
                }
                await deleteht_yys(yys.htbh, yys.nd, yys.yf);
                await insertht_yys(yys);
            }
            foreach (HT_ZCXX zcxx in co.zcxx)
            {
                 sql = "update assets set bw='"+zcxx.zcbw+"',zdj="+zcxx.zdj+ " where projcode='"+co.ht.xmbh+"'";
                await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            }
        }


        #endregion

        #region "租赁合同"
        public static async Task InsertHT_ZLHT(HT_ZLHT_Total ht)
        {
            HT_ZLHT zlht = ht.zlht;
            zlht.pgj = zlht.pgj == null?0:zlht.pgj;
            if (zlht.Listid == "")
            {
                string sql = @"delete from ht_zlht where htbh='"+zlht.htbh+ @"'; insert into ht_zlht ( htbh, sqr, sqbm, sqrq, cqrmc, cqrhm, cqrfrdb, cqrdbry, cqrlxdh, cqrfdzd, cqryb, cqrshxydm, cqrsfzhm, czrmc, czrfrdb, czrdbry, czrlxdh, czrfdzd, czryb, czrshxydm, 
                      czrsfzhm, dgfmc, dgffrdb, dgfdbry, dgflxdh, dgffdzd, dgfyb, dgfshxydm, dgfsfzhm, xmmc, htmc, htlx, sfxz, htqdrq, htqdksrq, htqdjsrq, htqx, htqddd, cfdd, htsm, zlyt, htjzmj, htsymj, gtmj, czmj, zxkssj, 
                      zxjssj, zxqx, qqqmq, zlkssj, zljssj, zlq, zjfs, fkzq, sfrq, sfje, ck, yzj, ysdf, zzj, wyxz, ywyf, skqx, sz, pt, qt, skgz, tqjcx, htqd, tqjy, tqjch, xzx, wyj, jfwyj, yfwyj, bhtyts, jfz, yfz, bfz, zt,
                    bmdm,czrzhbh,cqrkhh,cqryhzh,czrlx,czrhm,czrkhh,czryhzh,xmbh,zzjgdm,zzjgmc,cjrq,ptjybh,znjbl,jylx,yhtbh,pgj,sssq,bz,kplx,sssqbm,zybm,qtsm,skfsx,cqrdm)
            values ('" + zlht.htbh+"','"+zlht. sqr+"','"+zlht. sqbm+"','"+zlht. sqrq+"','"+zlht. cqrmc+"','"+zlht. cqrhm+"','"+zlht. cqrfrdb+"','"+zlht. cqrdbry+"','"+zlht. cqrlxdh+"','"+zlht. cqrfdzd+"','"+zlht. cqryb+"','"+zlht. cqrshxydm+"','"+zlht. cqrsfzhm+"','"+zlht. czrmc+"','"+zlht. czrfrdb+"','"+zlht. czrdbry+"','"+zlht. czrlxdh+"','"+zlht. czrfdzd+"','"+zlht. czryb+"','"+zlht. czrshxydm+"','"+zlht. 
                      czrsfzhm+"','"+zlht. dgfmc+"','"+zlht. dgffrdb+"','"+zlht. dgfdbry+"','"+zlht. dgflxdh+"','"+zlht. dgffdzd+"','"+zlht. dgfyb+"','"+zlht. dgfshxydm+"','"+zlht. dgfsfzhm+"','"+zlht. xmmc+"','"+zlht. htmc+"','"+zlht. htlx+"','"+zlht. sfxz+"','"+zlht. htqdrq+"','"+zlht. htqdksrq+"','"+zlht. htqdjsrq+"','"+zlht. htqx+"','"+zlht. htqddd+"','"+zlht. cfdd+"','"+zlht. htsm+"','"+zlht. zlyt+"','"+zlht. htjzmj+"','"+zlht. htsymj+"','"+zlht. gtmj+"','"+zlht. czmj+"','"+zlht. zxkssj+"','"+zlht. 
                      zxjssj+"','"+zlht. zxqx+"','"+zlht. qqqmq+"','"+zlht. zlkssj+"','"+zlht. zljssj+"','"+zlht. zlq+"','"+zlht. zjfs+"','"+zlht. fkzq+"','"+zlht. sfrq+"','"+zlht. sfje+"','"+zlht. ck+"','"+zlht. yzj+"','"+zlht. ysdf+"','"+zlht. zzj+"','"+zlht. wyxz+"','"+zlht. ywyf+"','"+zlht. skqx+"','"+zlht. sz+"','"+zlht. pt+"','"+zlht. qt+"','"+zlht. skgz+"','"+zlht. tqjcx+"','"+zlht. htqd+"','"+
                      zlht. tqjy+"','"+zlht. tqjch+"','"+zlht. xzx+"','"+zlht. wyj+"','"+zlht. jfwyj+"','"+zlht. yfwyj+"','"+zlht. bhtyts+"','"+zlht. jfz+"','"+zlht. yfz+"','"+zlht. bfz+"','1','"
                      +zlht. bmdm+"','"+zlht.czrzhbh+ "','"+ zlht.cqrkhh+"','"+ zlht.cqryhzh+"','"+zlht.czrlx+"','" + zlht.czrhm + "','" + zlht.czrkhh + "','" + zlht.czryhzh + "','" + zlht.xmbh 
                      + "','" + zlht.zzjgdm + "','" + zlht.zzjgmc + "','" + zlht.cjrq + "','" + zlht.ptjybh + "','" + zlht.znjbl + "','"+zlht.jylx+"','"+zlht.yhtbh+"','"+zlht.pgj+"','"+
                      zlht.sssq+"','"+zlht.bz+"','"+zlht.kplx+"','"+zlht.sssqbm+"','"+zlht.zybm+"','"+zlht.qtsm+"','"+zlht.skfsx + "','"+zlht.cqrdm+"'); ";

                sql += "update ht_zlht set htqdrq=null where htqdrq='1900-01-01 00:00:00.000' and htbh='" + zlht.htbh + "' ; ";
                sql += "update ht_zlht set htqdksrq=null where htqdksrq='1900-01-01 00:00:00.000' and htbh='" + zlht.htbh + "' ; ";
                sql += "update ht_zlht set htqdjsrq=null where htqdjsrq='1900-01-01 00:00:00.000' and htbh='" + zlht.htbh + "' ; ";
                sql += "update ht_zlht set zxkssj=null where zxkssj='1900-01-01 00:00:00.000' and htbh='" + zlht.htbh + "' ; ";
                sql += "update ht_zlht set zxjssj=null where zxjssj='1900-01-01 00:00:00.000' and htbh='" + zlht.htbh + "' ; ";
                sql += "update ht_zlht set zlkssj=null where zlkssj='1900-01-01 00:00:00.000' and htbh='" + zlht.htbh + "' ; ";
                sql += "update ht_zlht set zljssj=null where zljssj='1900-01-01 00:00:00.000' and htbh='" + zlht.htbh + "' ; ";
                sql += "update ht_zlht set sfrq=null where sfrq='1900-01-01 00:00:00.000' and htbh='" + zlht.htbh + "' ; ";

                await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            }
            else
            {
                await UpdateHT_ZLHT(zlht);
            }
            await DeleteHT_ZCXX(zlht.htbh);
            foreach (HT_ZCXX zcxx in ht.zcxx)
            {
                await InsertHT_ZCXX(zcxx);
            }
            await DeleteHT_SKJH(zlht.htbh);
            foreach (HT_SKJH skjh in ht.skjh)
            {
                await InsertHT_SKJH(skjh);
            }
            await DeleteHT_BZJ(zlht.htbh);
            foreach (HT_BZJ bzj in ht.bzj)
            {
                await InsertHT_BZJ(bzj);
            }
            await DeleteHT_ZLHT_BDZJ(zlht.htbh);
            foreach (HT_ZLHT_BDZJ bdzj in ht.bdzj)
            {
                await InsertHT_ZLHT_BDZJ(bdzj);
            }
            await DeleteHT_HTZXBM(zlht.htbh);
            foreach (HT_Htzxbm htzxbm in ht.htzxbm)
            {
                await InsertHT_HTZXBM(htzxbm);
            }
            await deleteht_srqrb(zlht.htbh);
            if (ht.srqrb != null)
            {
                foreach (ht_srqrb sr in ht.srqrb)
                {
                    if (string.IsNullOrEmpty(sr.htbh))
                    {
                        sr.htbh = zlht.htbh;
                    }
                    await insertht_srqrb(sr);
                }
            }
            if (ht.yys != null)
            {
                foreach (ht_yys yys in ht.yys)
                {
                    if (string.IsNullOrEmpty(yys.htbh))
                    {
                        yys.htbh = zlht.htbh;
                    }
                    await deleteht_yys(yys.htbh, yys.nd, yys.yf);
                    await insertht_yys(yys);
                }
            }
        }



        public static async Task deleteht_yys(string htbh, string nd,string yf)
        {
            string sql = "delete from ht_yys where htbh='"+htbh+"' and nd='"+nd+"' and yf='"+yf+"'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }

        public static async Task insertht_yys(ht_yys yys)
        {
            await new RepositoryFactory().BaseRepository().Insert(yys);
        }

        public static async Task deleteht_srqrb(string htbh)
        {
            string sql = "delete from ht_srqrb where htbh='"+htbh+"'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }
        public static async Task insertht_srqrb(ht_srqrb srqrb)
        {
            await new RepositoryFactory().BaseRepository().Insert(srqrb);
        }

        public static async Task InsertHT_ZLHT_LF(HT_ZLHT_Total ht)
        {
            HT_ZLHT zlht = ht.zlht;
            await DeleteHT_ZLHT(zlht.htbh);
          
                string sql = @"insert into ht_zlht ( htbh, sqr, sqbm, sqrq, cqrmc, cqrhm, cqrfrdb, cqrdbry, cqrlxdh, cqrfdzd, cqryb, cqrshxydm, cqrsfzhm, czrmc, czrfrdb, czrdbry, czrlxdh, czrfdzd, czryb, czrshxydm, 
                      czrsfzhm, dgfmc, dgffrdb, dgfdbry, dgflxdh, dgffdzd, dgfyb, dgfshxydm, dgfsfzhm, xmmc, htmc, htlx, sfxz, htqdrq, htqdksrq, htqdjsrq, htqx, htqddd, cfdd, htsm, zlyt, htjzmj, htsymj, gtmj, czmj, zxkssj, 
                      zxjssj, zxqx, qqqmq, zlkssj, zljssj, zlq, zjfs, fkzq, sfrq, sfje, ck, yzj, ysdf, zzj, wyxz, ywyf, skqx, sz, pt, qt, skgz, tqjcx, htqd, tqjy, tqjch, xzx, wyj, jfwyj, yfwyj, bhtyts, jfz, yfz, bfz, zt, bmdm,czrzhbh,cqrkhh,cqryhzh,czrlx,czrhm,czrkhh,czryhzh,xmbh,zzjgdm,zzjgmc,cjrq,ptjybh,znjbl,jylx,yhtbh)
            values ('" + zlht.htbh + "','" + zlht.sqr + "','" + zlht.sqbm + "','" + zlht.sqrq + "','" + zlht.cqrmc + "','" + zlht.cqrhm + "','" + zlht.cqrfrdb + "','" + zlht.cqrdbry + "','" + zlht.cqrlxdh + "','" + zlht.cqrfdzd + "','" + zlht.cqryb + "','" + zlht.cqrshxydm + "','" + zlht.cqrsfzhm + "','" + zlht.czrmc + "','" + zlht.czrfrdb + "','" + zlht.czrdbry + "','" + zlht.czrlxdh + "','" + zlht.czrfdzd + "','" + zlht.czryb + "','" + zlht.czrshxydm + "','" + zlht.
                      czrsfzhm + "','" + zlht.dgfmc + "','" + zlht.dgffrdb + "','" + zlht.dgfdbry + "','" + zlht.dgflxdh + "','" + zlht.dgffdzd + "','" + zlht.dgfyb + "','" + zlht.dgfshxydm + "','" + zlht.dgfsfzhm + "','" + zlht.xmmc + "','" + zlht.htmc + "','" + zlht.htlx + "','" + zlht.sfxz + "','" + zlht.htqdrq + "','" + zlht.htqdksrq + "','" + zlht.htqdjsrq + "','" + zlht.htqx + "','" + zlht.htqddd + "','" + zlht.cfdd + "','" + zlht.htsm + "','" + zlht.zlyt + "','" + zlht.htjzmj + "','" + zlht.htsymj + "','" + zlht.gtmj + "','" + zlht.czmj + "','" + zlht.zxkssj + "','" + zlht.
                      zxjssj + "','" + zlht.zxqx + "','" + zlht.qqqmq + "','" + zlht.zlkssj + "','" + zlht.zljssj + "','" + zlht.zlq + "','" + zlht.zjfs + "','" + zlht.fkzq + "','" + zlht.sfrq + "','" + zlht.sfje + "','" + zlht.ck + "','" + zlht.yzj + "','" + zlht.ysdf + "','" + zlht.zzj + "','" + zlht.wyxz + "','" + zlht.ywyf + "','" + zlht.skqx + "','" + zlht.sz + "','" + zlht.pt + "','" + zlht.qt + "','" + zlht.skgz + "','" + zlht.tqjcx + "','" + zlht.htqd + "','" + zlht.tqjy + "','" + zlht.tqjch + "','" + zlht.xzx + "','" + zlht.wyj + "','" + zlht.jfwyj + "','" + zlht.yfwyj + "','" + zlht.bhtyts + "','" + zlht.jfz + "','" + zlht.yfz + "','" + zlht.bfz + "','3','" + zlht.bmdm + "','" + zlht.czrzhbh + "','" + zlht.cqrkhh + "','" + zlht.cqryhzh + "','" + zlht.czrlx + "','" + zlht.czrhm + "','" + zlht.czrkhh + "','" + zlht.czryhzh + "','" + zlht.xmbh + "','" + zlht.zzjgdm + "','" + zlht.zzjgmc + "','" + zlht.cjrq + "','" + zlht.ptjybh + "','" + zlht.znjbl + "','" + zlht.jylx + "','" + zlht.yhtbh + "'); ";

                sql += "update ht_zlht set htqdrq=null where htqdrq='1900-01-01 00:00:00.000' and htbh='" + zlht.htbh + "' ; ";
                sql += "update ht_zlht set htqdksrq=null where htqdksrq='1900-01-01 00:00:00.000' and htbh='" + zlht.htbh + "' ; ";
                sql += "update ht_zlht set htqdjsrq=null where htqdjsrq='1900-01-01 00:00:00.000' and htbh='" + zlht.htbh + "' ; ";
                sql += "update ht_zlht set zxkssj=null where zxkssj='1900-01-01 00:00:00.000' and htbh='" + zlht.htbh + "' ; ";
                sql += "update ht_zlht set zxjssj=null where zxjssj='1900-01-01 00:00:00.000' and htbh='" + zlht.htbh + "' ; ";
                sql += "update ht_zlht set zlkssj=null where zlkssj='1900-01-01 00:00:00.000' and htbh='" + zlht.htbh + "' ; ";
                sql += "update ht_zlht set zljssj=null where zljssj='1900-01-01 00:00:00.000' and htbh='" + zlht.htbh + "' ; ";
                sql += "update ht_zlht set sfrq=null where sfrq='1900-01-01 00:00:00.000' and htbh='" + zlht.htbh + "' ; ";
            sql += "update ht_zlht set bmdm =(select bmdm from ht_PermissionCode where zzjgdm='"+zlht.zzjgdm+"') where htbh='"+zlht.htbh+"' and xmbh='"+zlht.xmbh+"' ; ";
                await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
          
           
            await DeleteHT_ZCXX(zlht.htbh);
            foreach (HT_ZCXX zcxx in ht.zcxx)
            {
                sql = "insert into HT_ZCXX(HTBH,zcbh,zcmc,zcbw,zclx,zcyt,jylx,ssdw,mjsl,cjj,jgdw,jydw) values ('" + zlht.htbh + "','" + zcxx.zcbh + "','" + zcxx.zcmc + "','" + zcxx.zcbw + "','" + zcxx.zclx + "','" + zcxx.zcyt + "','" + zcxx.jylx + "','" + zcxx.ssdw + "','" + zcxx.mjsl + "','" + zcxx.cjj + "','" + zcxx.jgdw + "','" + zcxx.jydw + "') ; ";

                await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            }
            //await DeleteHT_SKJH(zlht.htbh);
            //foreach (HT_SKJH skjh in ht.skjh)
            //{
            //    await InsertHT_SKJH(skjh);
            //}
            await DeleteHT_BZJ(zlht.htbh);
            foreach (HT_BZJ bzj in ht.bzj)
            {
                sql = "insert into ht_BZJ(HTBH,bzjje,bzjdzsj,thje,thsj,sjthsj,sfth,zt,htlx,htmc,dzje) values ('" + zlht.htbh + "','" + bzj.bzjje + "','" + bzj.bzjdzsj + "','" + bzj.thje + "','" + bzj.thsj + "','" + bzj.sjthsj + "','" + bzj.sfth + "','1','" + bzj.htlx + "','" + bzj.htmc + "','" + bzj.dzje + "') ; ";
                sql += "update HT_bzj set sjthsj=null where sjthsj='1900-01-01 00:00:00.000' and htbh='" + zlht.htbh + "' ; ";
                sql += "update HT_bzj set bzjdzsj=null where bzjdzsj='1900-01-01 00:00:00.000' and htbh='" + zlht.htbh + "' ; ";
                sql += "update HT_bzj set thsj=null where thsj='1900-01-01 00:00:00.000' and htbh='" + zlht.htbh + "' ; ";
                await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

            }
            // await DeleteHT_ZLHT_BDZJ(zlht.htbh);
            //foreach (HT_ZLHT_BDZJ bdzj in ht.bdzj)
            //{
            //    await InsertHT_ZLHT_BDZJ(bdzj);
            //}
            await DeleteHT_ZLHT_FILE(zlht.htbh);
            foreach (HT_FILE file in ht.file)
            {
                sql = "insert into HT_FILE(HTBH,filename,fileurl) values ('" + zlht.htbh + "','" + file.filename + "','" + file.fileurl + "');";
                await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            }
        }

        public static async Task UpdateHT_ZLHT(HT_ZLHT ht)
        {
            string sql = @"update ht_zlht set    sqr='" + ht.sqr + "',	 sqbm='" + ht.sqbm + "',	 sqrq='" + ht.sqrq + "',	 cqrmc='" + ht.cqrmc + "',	 cqrhm='" + ht.cqrhm + "',	 cqrfrdb='" + ht.cqrfrdb + "',	" +
                " cqrdbry='" + ht.cqrdbry + "',	 cqrlxdh='" + ht.cqrlxdh + "',	 cqrfdzd='" + ht.cqrfdzd + "',	 cqryb='" + ht.cqryb + "',	 cqrshxydm='" + ht.cqrshxydm + "',	 cqrsfzhm='" + ht.cqrsfzhm + "',czrzhbh='"+ht.czrzhbh+"',	" +
                " czrmc='" + ht.czrmc + "',	 czrfrdb='" + ht.czrfrdb + "',	 czrdbry='" + ht.czrdbry + "',	 czrlxdh='" + ht.czrlxdh + "',	 czrfdzd='" + ht.czrfdzd + "',	 czryb='" + ht.czryb + "',	 czrshxydm='" + ht.czrshxydm + "',	" +
                " czrsfzhm='" + ht.czrsfzhm + "',	 dgfmc='" + ht.dgfmc + "',	 dgffrdb='" + ht.dgffrdb + "',	 dgfdbry='" + ht.dgfdbry + "',	 dgflxdh='" + ht.dgflxdh + "',	 dgffdzd='" + ht.dgffdzd + "',	 dgfyb='" + ht.dgfyb + "',	" +
                " dgfshxydm='" + ht.dgfshxydm + "',	 dgfsfzhm='" + ht.dgfsfzhm + "',	 xmmc='" + ht.xmmc + "',	 htmc='" + ht.htmc + "',	 htlx='" + ht.htlx + "',	 sfxz='" + ht.sfxz + "',	 htqdrq='" + ht.htqdrq + "',	" +
                " htqdksrq='" + ht.htqdksrq + "',	 htqdjsrq='" + ht.htqdjsrq + "',	 htqx='" + ht.htqx + "',	 htqddd='" + ht.htqddd + "',	 cfdd='" + ht.cfdd + "',	 htsm='" + ht.htsm + "',	 zlyt='" + ht.zlyt + "',	" +
                " htjzmj='" + ht.htjzmj + "',	 htsymj='" + ht.htsymj + "',	 gtmj='" + ht.gtmj + "',	 czmj='" + ht.czmj + "',	 zxkssj='" + ht.zxkssj + "',	 zxjssj='" + ht.zxjssj + "',	 zxqx='" + ht.zxqx + "',	" +
                " qqqmq='" + ht.qqqmq + "',	 zlkssj='" + ht.zlkssj + "',	 zljssj='" + ht.zljssj + "',	 zlq='" + ht.zlq + "',	 zjfs='" + ht.zjfs + "',	 fkzq='" + ht.fkzq + "',	 sfrq='" + ht.sfrq + "',	 sfje='" + ht.sfje + "',	" +
                " ck='" + ht.ck + "',	 yzj='" + ht.yzj + "',	 ysdf='" + ht.ysdf + "',	 zzj='" + ht.zzj + "',	 wyxz='" + ht.wyxz + "',	 ywyf='" + ht.ywyf + "',	 skqx='" + ht.skqx + "',	 sz='" + ht.sz + "',	 pt='" + ht.pt + "',	" +
                " qt='" + ht.qt + "',	 skgz='" + ht.skgz + "',	 tqjcx='" + ht.tqjcx + "',	 htqd='" + ht.htqd + "',	 tqjy='" + ht.tqjy + "',	 tqjch='" + ht.tqjch + "',	 xzx='" + ht.xzx + "',	 wyj='" + ht.wyj + "',	" +
                " jfwyj='" + ht.jfwyj + "',	 yfwyj='" + ht.yfwyj + "',	 bhtyts='" + ht.bhtyts + "',	 jfz='" + ht.jfz + "',	 yfz='" + ht.yfz + "',	 bfz='" + ht.bfz + "',	 zt='" + ht.zt + "',	 bmdm='" + ht.bmdm + "',cqrkhh='"+ ht.cqrkhh + "'," +
                "cqryhzh='"+ ht.cqryhzh + "',czrlx='"+ ht.czrlx + "',czrhm='"+ ht.czrhm + "',czrkhh='"+ ht.czrkhh + "',czryhzh='"+ ht.czryhzh + "',xmbh='"+ ht.xmbh + "',zzjgdm='"+ ht.zzjgdm + "',zzjgmc='"+ ht.zzjgmc + "',cjrq='"+ ht.cjrq + "'," +
                "ptjybh='"+ ht.ptjybh + "',znjbl='"+ ht.znjbl + "',jylx='"+ht.jylx+"',yhtbh='"+ht.yhtbh+"',pgj='"+ht.pgj+"',bz='"+ht.bz+ "',sssq='"+ht.sssq+ "',kplx='"+ht.kplx+ "',sssqbm='"+ht.sssqbm+"'" +
                ",zybm='"+ht.zybm+ "',skfsx='"+ht.skfsx+ "',cqrdm='"+ht.cqrdm+"' where listid='" + ht.Listid + "' and htbh='"+ht.htbh+"'	  ; ";
            sql += "update ht_zlht set htqdrq=null where htqdrq='1900-01-01 00:00:00.000' and htbh='" + ht.htbh + "' ; ";
            sql += "update ht_zlht set htqdksrq=null where htqdksrq='1900-01-01 00:00:00.000' and htbh='" + ht.htbh + "' ; ";
            sql += "update ht_zlht set htqdjsrq=null where htqdjsrq='1900-01-01 00:00:00.000' and htbh='" + ht.htbh + "' ; ";
            sql += "update ht_zlht set zxkssj=null where zxkssj='1900-01-01 00:00:00.000' and htbh='" + ht.htbh + "' ; ";
            sql += "update ht_zlht set zxjssj=null where zxjssj='1900-01-01 00:00:00.000' and htbh='" + ht.htbh + "' ; ";
            sql += "update ht_zlht set zlkssj=null where zlkssj='1900-01-01 00:00:00.000' and htbh='" + ht.htbh + "' ; ";
            sql += "update ht_zlht set zljssj=null where zljssj='1900-01-01 00:00:00.000' and htbh='" + ht.htbh + "' ; ";
            sql += "update ht_zlht set sfrq=null where sfrq='1900-01-01 00:00:00.000' and htbh='" + ht.htbh + "' ; ";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }

        public static async Task<DataTable> DeleteHT_ZLHT(string htbh)
        {


            string sql = "delete HT_ZLHT where htbh='" + htbh + "';";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        #endregion
        #region "通用收款合同"
        public static async Task InsertHT_TYSKHT(HT_TYSKHT_Total ht)
        {
            HT_TYSKHT tyskht = ht.tyskht;
            if (tyskht.Listid == "")
            {
                string sql = @"delete from HT_tyskht where htbh='"+tyskht.htbh+@"'; insert into HT_tyskht (sqr, sqbm, sqrq, jfmc, jffrdb, jfdbry, jflxdh, jffdzd, jfyb, jfshxydm, jfsfzhm, htmc, htbh, htqdrq, htje, htkssj, htjssj, jkfs, cfdd, htqddd, fkzytj, htgfzyyw, wyzr, qtsx, zt,bmdm,skgz)
            values('" + tyskht.sqr + "','" + tyskht.sqbm + "','" + tyskht.sqrq + "','" + tyskht.jfmc + "','" + tyskht.jffrdb + "','" + tyskht.jfdbry + "','" + tyskht.jflxdh + "','" + tyskht.jffdzd + "','" + tyskht.jfyb + "','" + tyskht.jfshxydm + "','" + tyskht.jfsfzhm + "','" + tyskht.htmc + "','" + tyskht.htbh + "','" + tyskht.htqdrq + "','" + tyskht.htje + "','" + tyskht.htkssj + "','" + tyskht.htjssj + "','" + tyskht.jkfs + "','" + tyskht.cfdd + "','" + tyskht.htqddd + "','" + tyskht.fkzytj + "','" + tyskht.htgfzyyw + "','" + tyskht.wyzr + "','" + tyskht.qtsx + "','1','"+tyskht.bmdm+"','"+tyskht.skgz+"' );  ";
                await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            }
            else
            {
                await UpdateHT_TYSKHT(tyskht);
            }
            await DeleteHT_BDWXX(tyskht.htbh);
            foreach (HT_BDWXX bdwxx in ht.bdwxx)
            {
                await InsertHT_BDWXX(bdwxx);
            }
            await DeleteHT_SKJH(tyskht.htbh);
            foreach (HT_SKJH skjh in ht.skjh)
            {
                await InsertHT_SKJH(skjh);
            }
            await DeleteHT_BZJ(tyskht.htbh);
            foreach (HT_BZJ bzj in ht.bzj)
            {
                await InsertHT_BZJ(bzj);
            }
            await DeleteHT_YFXX(tyskht.htbh);
            foreach (HT_YFXX yfxx in ht.yfxx)
            {
                await InsertHT_YFXX(yfxx);
            }
            await DeleteHT_HTZXBM(tyskht.htbh);
            foreach (HT_Htzxbm htzxbm in ht.htzxbm)
            {
                await InsertHT_HTZXBM(htzxbm);
            }

        }
        public static async Task UpdateHT_TYSKHT(HT_TYSKHT ht)
        {
            string sql = @"update ht_tyskht set sqr='" + ht.sqr + "', sqbm='" + ht.sqbm + "', sqrq='" + ht.sqrq + "', jfmc='" + ht.jfmc + "', jffrdb='" + ht.jffrdb + "', jfdbry='" + ht.jfdbry + "', jflxdh='" + ht.jflxdh + "', jffdzd='" + ht.jffdzd + "', jfyb='" + ht.jfyb + "', jfshxydm='" + ht.jfshxydm + "', jfsfzhm='" + ht.jfsfzhm + "', htqdrq='" + ht.htqdrq + "', htje='" + ht.htje + "', htkssj='" + ht.htkssj + "', htjssj='" + ht.htjssj + "', jkfs='" + ht.jkfs + "', cfdd='" + ht.cfdd + "', htqddd='" + ht.htqddd + "', fkzytj='" + ht.fkzytj + "', htgfzyyw='" + ht.htgfzyyw + "', wyzr='" + ht.wyzr + "', qtsx='" + ht.qtsx + "',zt='1' , htmc='" + ht.htmc + "',bmdm='"+ht.bmdm+"'  where 	 listid='" + ht.Listid + "' and htbh='"+ht.htbh+"' ; ";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }





        #endregion

        #region "标的物信息"
        public static async Task<DataTable> GetHT_BDWXX(string htbh, string bgdh)
        {
            string sql = "";
            if (bgdh != "" && bgdh != null)
            {
               sql = "select listid,HTBH,zclb,pmmc,pmbm,zyjscs,ggxh,jldw,dj,sl,zj,zt,spmc,isnull(yyssl,0) as yyssl,isnull(dyssl,0) as dyssl,isnull(yysje,0) as yysje,isnull(dysje,0) as dysje from HT_BDWXX_bgd where bgdh='" + bgdh + "'  ;";
            }
            else
            {
                sql = "select listid,HTBH,zclb,pmmc,pmbm,zyjscs,ggxh,jldw,dj,sl,zj,zt,spmc,isnull(yyssl,0) as yyssl,isnull(dyssl,0) as dyssl,isnull(yysje,0) as yysje,isnull(dysje,0) as dysje from HT_BDWXX where htbh='" + htbh + "'  ;";

            }

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> DeleteHT_BDWXX(string htbh)
        {


            string sql = "delete ht_bdwxx where htbh='" + htbh + "' ";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> InsertHT_BDWXX(HT_BDWXX ht)
        {
            string sql = "";
            //if (ht.Listid == "")
            //{
                sql = "insert into ht_bdwxx(HTBH,zclb,spmc,ggxh,dj,sl,zj,zt,pmmc,pmbm,zyjscs,jldw) values ('" + ht.htbh + "','" + ht.zclb + "','"+ht.spmc+"','" + ht.ggxh + "','" + ht.dj + "','" + ht.sl + "','" + ht.zj + "','"+ht.zt+"','"+ht.pmmc+"','"+ht.pmbm+"','"+ht.zyjscs+"','"+ht.jldw+"') ";
            //}
            //else
            //{
            //    sql = "update ht_bdwxx set htbh='" + ht.htbh + "',zclb='" + ht.zclb + "',spmc='"+ht.spmc+"',ggxh='" + ht.ggxh + "',dj='" + ht.dj + "',sl='" + ht.sl + "',zj='" + ht.zj + "',zt='" + ht.zt + "',pmmc='"+ht.pmmc+"',pmbm='"+ht.pmbm+"',zyjscs='"+ht.zyjscs+"',jldw='"+ht.jldw+"' where listid='" + ht.Listid + "' ";
            //}

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> DeleteHT_BDWXX_BGD(string htbh,string bgdh)
        {


            string sql = "delete ht_bdwxx_BGD where BGDH='" + bgdh + "' and  htbh='"+htbh+"';";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> InsertHT_BDWXX_BGD(HT_BDWXX ht)
        {
            string sql = "";
            //if (ht.Listid == "")
            //{
            sql = "insert into ht_bdwxx_bgd(HTBH,zclb,spmc,ggxh,dj,sl,zj,zt,pmmc,pmbm,zyjscs,jldw,bgdh) values ('" + ht.htbh + "','" + ht.zclb + "','" + ht.spmc + "','" + ht.ggxh + "','" + ht.dj + "','" + ht.sl + "','" + ht.zj + "','" + ht.zt + "','" + ht.pmmc + "','" + ht.pmbm + "','" + ht.zyjscs + "','" + ht.jldw + "','"+ht.bgdh+"');";
            //}
            //else
            //{
            //    sql = "update ht_bdwxx set htbh='" + ht.htbh + "',zclb='" + ht.zclb + "',spmc='"+ht.spmc+"',ggxh='" + ht.ggxh + "',dj='" + ht.dj + "',sl='" + ht.sl + "',zj='" + ht.zj + "',zt='" + ht.zt + "',pmmc='"+ht.pmmc+"',pmbm='"+ht.pmbm+"',zyjscs='"+ht.zyjscs+"',jldw='"+ht.jldw+"' where listid='" + ht.Listid + "' ";
            //}

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        #endregion
        #region "收款账号"
        public static async Task<DataTable> GetHT_SKZH(string htbh, string bgdh)
        {
            string sql = "";
            if (bgdh != "" && bgdh != null)
            {
                 sql = "select * from ht_SKZH_bgd where bgdh='" + bgdh + "' ;";
            }
            else
            {
                sql = "select * from ht_SKZH where htbh='" + htbh + "' ;";


            }

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> DeleteHT_SKZH(string htbh)
        {


            string sql = "delete ht_SKZH where htbh='" + htbh + "';";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> InsertHT_SKZH(HT_SKZH ht)
        {
            string sql = "";
            //if (ht.Listid == "")
            //{
                sql = "insert into HT_SKZH(HTBH,gys,nsrsbh,khh,skzh,lxr,lxdh,zt) values ('" + ht.htbh + "','" + ht.gys + "','" + ht.nsrsbh + "','" + ht.khh + "','" + ht.skzh + "','" + ht.lxr + "','" + ht.lxdh + "','1');";
            //}
            //else
            //{
            //    sql = "update HT_SKZH set htbh='" + ht.htbh + "',gys='" + ht.gys + "',nsrsbh='" + ht.nsrsbh + "',khh='" + ht.khh + "',skzh='" + ht.skzh + "',lxr='" + ht.lxr + "',lxdh='" + ht.lxdh + "',zt='" + ht.zt + "' where listid='" + ht.Listid + "' ";
            //}



            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> DeleteHT_SKZH_BGD(string htbh,string bgdh)
        {


            string sql = "delete ht_SKZH_bgd where htbh='" + htbh + "' and bgdh='"+bgdh+"';";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> InsertHT_SKZH_BGD(HT_SKZH ht)
        {
            string sql = "";
           
            sql = "insert into HT_SKZH_bgd (HTBH,gys,nsrsbh,khh,skzh,lxr,lxdh,zt,bgdh) values ('" + ht.htbh + "','" + ht.gys + "','" + ht.nsrsbh + "','" + ht.khh + "','" + ht.skzh + "','" + ht.lxr + "','" + ht.lxdh + "','1','"+ht.bgdh+"');";
  
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> GetHT_SKYH(string htid)
        {
            string sql = "";

            sql = "select htbh as htid,gys as hm,khh as yhmc,skzh as yhzh from ht_skzh where htbh='" + htid + "' ;";

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> GetHT_SKYHx(string htid)
        {
            string sql = "";

            sql = "select htid as htid,dwmc as hm,yhmc as yhmc,yhzh as yhzh from BConstructionUnitsYH  where htid='"+htid+"'";

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }


        #endregion
        #region "付款计划"
        public static async Task<DataTable> GetHT_FKJH(string htbh, string bgdh)
        {
            string sql = "";
            if (bgdh != "" && bgdh != null)
            {

                sql = "select ListID, HTBH, jhnr, fkbl, fkje, convert(varchar(10),fksj,120) fksj, fktj, zt from ht_FKJH_bgd where bgdh='" + bgdh + "'  ";
            }
            else
            {

                 sql = "select LISTID , HTBH , JHNR , FKBL , FKJE , convert(varchar(10),fksj,120) as FKSJ  , FKTJ, ZT from ht_fkjh  where htbh='" + htbh + "' order by fksj ";

            }

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> DeleteHT_FKJH(string htbh)
        {


            string sql = "delete ht_FKJH where htbh='" + htbh + "';";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> InsertHT_FKJH(HT_FKJH ht)
        {
            string sql = "";
           
           
            sql = "insert into HT_FKJH(HTBH,jhnr,fkbl,fkje,fksj,fktj,zt) values ('" + ht.htbh + "','" + ht.jhnr + "','" + ht.fkbl + "','" + ht.fkje + "','" + ht.fksj + "','" + ht.fktj + "','1') ; ";
            sql += "update HT_FKJH set fksj=null where fksj='1900-01-01 00:00:00.000' and htbh='" + ht.htbh + "' ; ";
          
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> DeleteHT_FKJH_BGD(string htbh,string bgdh)
        {


            string sql = "delete ht_FKJH_BGD where htbh='" + htbh + "' and bgdh='"+bgdh+"';";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> InsertHT_FKJH_BGD(HT_FKJH ht)
        {
            string sql = "";


            sql = "insert into HT_FKJH_bgd(HTBH,jhnr,fkbl,fkje,fksj,fktj,zt,bgdh) values ('" + ht.htbh + "','" + ht.jhnr + "','" + ht.fkbl + "','" + ht.fkje + "','" + ht.fksj + "','" + ht.fktj + "','1','"+ht.bgdh+"') ; ";
            sql += "update HT_FKJH_bgd set fksj=null where fksj='1900-01-01 00:00:00.000' and htbh='" + ht.htbh + "' ; ";

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        #endregion
        #region "保证金"
        public static async Task<DataTable> GetHT_BZJ(string htbh, string bgdh)
        {
            string sql = "";
            if (bgdh != "" && bgdh!=null)
            {
                sql = "select  ListID, HTBH, bzjje, convert(varchar(10),bzjdzsj,120) bzjdzsj, thje, convert(varchar(10),thsj,120) thsj, sfth, zt, convert(varchar(10),sjthsj,120) sjthsj, htlx, htmc,dzje from ht_BZJ_bgd where htbh='" + htbh + "' and bgdh='" + bgdh + "' ; ";

            }
            else
            {
                sql = "select  ListID, HTBH, bzjje, convert(varchar(10),bzjdzsj,120) bzjdzsj, thje, convert(varchar(10),thsj,120) thsj, sfth, zt, convert(varchar(10),sjthsj,120) sjthsj, htlx, htmc,dzje from ht_BZJ where htbh='" + htbh + "' ; ";

            }


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> GetHT_BZJch(string Listid)
        {
            string sql = "";
           
                sql = "select  ListID, HTBH, bzjje, convert(varchar(10),bzjdzsj,120) bzjdzsj, thje, convert(varchar(10),thsj,120) thsj, sfth, zt, convert(varchar(10),sjthsj,120) sjthsj, htlx, htmc,dzje from ht_BZJ where listid='" + Listid + "' ; ";

         

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> DeleteHT_BZJ(string htbh)
        {


            string sql = "delete ht_BZJ where htbh='" + htbh + "';";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> DeleteHT_BZJ_BGD(string htbh,string bgdh)
        {


            string sql = "delete ht_BZJ_BGD where htbh='" + htbh + "' and bgdh='"+bgdh+"';";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task InsertHT_BZJ(HT_BZJ ht)
        {
            string sql = "";
       
                sql = "insert into ht_BZJ(HTBH,bzjje,bzjdzsj,thje,thsj,sjthsj,sfth,zt,htlx,htmc,dzje) values ('" + ht.htbh + "','" + ht.bzjje + "','" + ht.bzjdzsj + "','" + ht.thje + "','" + ht.thsj + "','"+ht.sjthsj+"','" + ht.sfth + "','1','"+ht.htlx+"','"+ht.htmc+"','"+ht.dzje+"') ; ";
            sql += "update HT_bzj set sjthsj=null where sjthsj='1900-01-01 00:00:00.000' and htbh='" + ht.htbh + "' ; ";
            sql += "update HT_bzj set bzjdzsj=null where bzjdzsj='1900-01-01 00:00:00.000' and htbh='" + ht.htbh + "' ; ";
            sql += "update HT_bzj set thsj=null where thsj='1900-01-01 00:00:00.000' and htbh='" + ht.htbh + "' ; ";
          
             await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }

        public static async Task UpdateHT_BZJ(HT_BZJ_Total ht)
        {
           await DeleteHT_BZJ(ht.htbh);
            foreach (HT_BZJ bzj in ht.bzj)
            {
                
                    await InsertHT_BZJ(bzj);

                
            }

        }

        public static async Task<DataTable> SoloHT_BZJ(HT_BZJ ht)
        {
            string sql = "";
            if(ht.type=="Insert")
            {
            sql = "insert into ht_BZJ(HTBH,bzjje,bzjdzsj,thje,thsj,sjthsj,sfth,zt,htlx,htmc,dzje) values ('" + ht.htbh + "','" + ht.bzjje + "','" + ht.bzjdzsj + "','" + ht.thje + "','" + ht.thsj + "','" + ht.sjthsj + "','" + ht.sfth + "','1','" + ht.htlx + "','" + ht.htmc + "','" + ht.dzje + "') ; ";
            sql += "update HT_bzj set sjthsj=null where sjthsj='1900-01-01 00:00:00.000' and htbh='" + ht.htbh + "' ; ";
            sql += "update HT_bzj set bzjdzsj=null where bzjdzsj='1900-01-01 00:00:00.000' and htbh='" + ht.htbh + "' ; ";
            sql += "update HT_bzj set thsj=null where thsj='1900-01-01 00:00:00.000' and htbh='" + ht.htbh + "' ; ";
            }
            if (ht.type == "Update")
            {
                sql = "update ht_BZJ set HTBH='"+ht.htbh+"',bzjje='"+ht.bzjje+"',bzjdzsj='"+ht.bzjdzsj+"',thje='"+ht.thje+"',thsj='"+ht.thsj+"',sjthsj='"+ht.sjthsj+"',sfth='"+ht.sfth+"',zt='"+ht.zt+"',htlx='"+ht.htlx+"',htmc='"+ht.htmc+"',dzje='"+ht.dzje+"'  where listid='"+ht.Listid+"' ; ";
                sql += "update HT_bzj set sjthsj=null where sjthsj='1900-01-01 00:00:00.000' and listid='" + ht.Listid + "' ; ";
                sql += "update HT_bzj set bzjdzsj=null where bzjdzsj='1900-01-01 00:00:00.000' and listid='" + ht.Listid + "' ; ";
                sql += "update HT_bzj set thsj=null where thsj='1900-01-01 00:00:00.000' and listid='" + ht.Listid + "' ; ";

            }
            if (ht.type == "Delete")
            {
                sql = "delete ht_BZJ where listid='"+ht.Listid+"' ; ";

            }
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> BackHT_BZJ(HT_BZJ_BACK ht)
        {
          
            string sql = "";
            if(ht.capitalProperty== "return")
            {
                sql = "update ht_BZJ set thje=isnull(dzje,0)+" + ht.arrivalAmount + "/100,sjthsj='" + ht.arrivalTime + "' where listid='" + ht.Listid + "' ; ";

            }
            if (ht.capitalProperty == "income")
            {
                sql = "update ht_BZJ set dzje=isnull(dzje,0)+" + ht.arrivalAmount + "/100,bzjdzsj='" + ht.arrivalTime + "' where listid='" + ht.Listid + "' ; ";

            }
            //sql += "update ht_BZJ set thje=dzje,sjthsj=bzjdzsj where listid='" + ht.Listid + "' ; ";

            sql += "update ht_BZJ set sfth='已退还' where listid='" + ht.Listid + "' and bzjje=dzje  ";

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        #endregion
        #region "租赁合同基本信息"
        public static async Task<DataTable> GetHT_ZLHT_JBXX(string htbh, string zt)
        {


            string sql = "select * from ht_ZLHT_JBXX where htbh='" + htbh + "' ;";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> DeleteHT_ZLHT_JBXX(string htbh)
        {


            string sql = "delete ht_ZLHT_JBXX where htbh='" + htbh + "';";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> InsertHT_ZLHT_JBXX(HT_ZLHT_JBXX ht)
        {

            string sql = "";
            //if (ht.Listid == "")
            //{
                sql = "insert into ht_ZLHT_JBXX(HTBH,bwmc,mj,zt) values ('" + ht.htbh + "','" + ht.bwmc + "','" + ht.mj + "','1');";
            //}
            //else
            //{
            //    sql = "update ht_ZLHT_JBXX set HTBH='" + ht.htbh + "',bwmc='" + ht.bwmc + "',mj='" + ht.mj + "',zt='" + ht.zt + "' where listid='" + ht.Listid + "' ";
            //}

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }



        #endregion
        #region "收款计划"
        public static async Task<DataTable> GetHT_SKJH(string htbh,string bgdh)
        {
            string sql = "";
            if (bgdh != "" && bgdh != null)
            {
                sql = "select ListID,htbh,skfs,qs,jhskbl,jhskje,convert(varchar(10),jhskrq,120) jhskrq,jhsknr,skqj,ssnd, skrq, skje " +
                    "from ht_SKJH_bgd a left join (select max(collectionTime) as skrq,projectCode,planid from vw_ht_skxx where collectiontype='已对账' and zt='3'" +
                    "group by projectCode,planid) b on a.htbh=b.projectCode and a.ListID=b.planid left join (select sum(CollectionAmount) as skje,projectCode,planid from vw_ht_skxx where collectiontype='已对账' and zt='3'" +
                    "group by projectCode,planid) c on a.htbh=c.projectCode and a.ListID=c.planid where htbh='" + htbh + "' and bgdh='" + bgdh + "'  order by jhskrq;";

            }
            else
            {
                sql = "select ListID,htbh,skfs,qs,jhskbl,jhskje,convert(varchar(10),jhskrq,120) jhskrq,jhsknr,skqj,ssnd,skrq,skje,qtsm from vw_ht_SKJH where htbh='" + htbh + "'  order by jhskrq;";

            }


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

      


        public static async Task<DataTable> DeleteHT_SKJH(string htbh)
        {


            string sql = "delete ht_SKJH where htbh='" + htbh + "' ";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> DeleteHT_SKJH_BGD(string htbh,string bgdh)
        {


            string sql = "delete ht_SKJH_BGD where htbh='" + htbh + "' and bgdh='"+bgdh+"';";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task InsertHT_SKJH(HT_SKJH ht)
        {

            string sql = "";
            if (ht.Listid == 0)
            {
                sql = "declare @id int;set @id=isnull((select max(listid) from ht_skjh),0)+1;insert into HT_SKJH(listid,htbh,skfs,qs,jhskbl,jhskje,jhskrq,jhsknr,skqj,ssnd) values (@id,'" + ht.htbh + "','" + ht.skfs + "','" + ht.qs + "','" + ht.jhskbl + "','" + ht.jhskje + "','" + ht.jhskrq + "','" + ht.jhsknr + "','" + ht.skqj + "','" + ht.ssnd + "') ; ";
                sql += "update HT_SKJH set jhskrq=null where jhskrq='1900-01-01 00:00:00.000' and htbh='" + ht.htbh + "' ; ";
                sql += "delete from ContractPlan where projcode='" + ht.htbh + "'; Insert into ContractPlan(projcode,fkfs,zqs,sqbl,je,skrq, bz,nd) select htbh,skfs,qs,jhskbl,jhskje,jhskrq,jhsknr,ssnd from HT_SKJH where htbh='" + ht.htbh + "'";
            }
            else
            {
                sql = "insert into HT_SKJH(listid,htbh,skfs,qs,jhskbl,jhskje,jhskrq,jhsknr,skqj,ssnd) values (" + ht.Listid + ",'" + ht.htbh + "','" + ht.skfs + "','" + ht.qs + "','" + ht.jhskbl + "','" + ht.jhskje + "','" + ht.jhskrq + "','" + ht.jhsknr + "','" + ht.skqj + "','" + ht.ssnd + "') ; ";
                sql += "update HT_SKJH set jhskrq=null where jhskrq='1900-01-01 00:00:00.000' and htbh='" + ht.htbh + "' ; ";
                sql += "delete from ContractPlan where projcode='" + ht.htbh + "'; Insert into ContractPlan(projcode,fkfs,zqs,sqbl,je,skrq, bz,nd) select htbh,skfs,qs,jhskbl,jhskje,jhskrq,jhsknr,ssnd from HT_SKJH where htbh='" + ht.htbh + "'";
            }

            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }


        public static async Task UpdateHT_SKJH(HT_SKJH_Total ht)
        {
            string htbh = ht.htbh;
            string skgz = ht.skgz;
            string sql = "update ht_zlht set skgz='"+skgz+"' where htbh='"+htbh+"' ; " ;
            sql += "update ht_tyskht set skgz='" + skgz + "' where htbh='" + htbh + "' ;";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

            await DeleteHT_SKJH(ht.htbh);
            foreach (HT_SKJH skjh in ht.skjh)
            {
                await InsertHT_SKJH(skjh);
            }

        }



        public static async Task<DataTable> InsertHT_SKXX(HT_SKXXx ht)
        {

            string sql = "";
            if (ht.collectiontype == "已开票" || ht.collectiontype == "已对账")
            {
                if (ht.contractType == "产交合同")
                {
                    sql = "insert into HT_SKXX(listid, projectCode, collectionTime, CollectionAmount, collectionAccount, collectionBank, collectionName, payAccount, payBank, payAmount, infoType,xmbh,serialNumber,paytime,planid,collectiontype,username,invoiceType,invoicingType,invoiceID,zt)" +
                        " values ('"+ht.listid+"', '" + ht.projectCode + "','" + ht.collectionTime + "'," + ht.CollectionAmount + ",'" + ht.collectionAccount + "','" + ht.collectionBank + "','" + ht.collectionName + "','" +
                        ht.payAccount + "','" + ht.payBank + "'," + ht.payAmount + ",'" + ht.infoType + "','" + ht.keyStr + "','" + ht.serialNumber + "','" + ht.paytime + "','" + ht.planid + "','" + ht.collectiontype + "','"+ht.username+"','"+ht.invoiceType+"','"+ht.invoicingType + "','"+ ht.invoiceID + "','3') ;  ";
                    sql += "delete HT_AssetsZF where xmbh='" + ht.keyStr + "'; ";
                    //  sql += "insert into HT_AssetsZF(HTBH, XMBH, zfje) values('"+ht.projectCode+"','"+ht.xmbh+ "'," + ht.CollectionAmount + "/100) ; ";
                    sql += "insert into HT_AssetsZF(HTBH, XMBH, zfje) select '" + ht.projectCode + "','" + ht.keyStr + "',sum(isnull(CollectionAmount,0)) from HT_SKXX where xmbh='" + ht.keyStr + "'; ";


                }
                else
                {
                    sql = "insert into HT_SKXX(listid, projectCode, collectionTime, CollectionAmount, collectionAccount, collectionBank, collectionName, payAccount, payBank, payAmount, infoType,xmbh,serialNumber,paytime,planid,collectiontype,username,invoiceType,invoicingType,invoiceID)" +
                        " values ( '"+ht.listid+"','" + ht.projectCode + "','" + ht.collectionTime + "'," + ht.CollectionAmount + ",'" + ht.collectionAccount + "','" + ht.collectionBank + "','" + ht.collectionName + "','" +
                        ht.payAccount + "','" + ht.payBank + "'," + ht.payAmount + ",'" + ht.infoType + "','','" + ht.serialNumber + "','" + ht.paytime + "','" + ht.planid + "','" + ht.collectiontype + "','"+ht.username + "','" + ht.invoiceType + "','" + ht.invoicingType+"','"+ht.invoiceID + "') ;  ";

                }
            }
            else if (ht.collectiontype == "开票取消")
            {
                sql = "delete from HT_SKXX where serialNumber='" + ht.serialNumber + "' and collectiontype='已开票' and planid='"+ht.planid+ "' and invoiceID='"+ht.invoiceID+"'";
            }
            //else if (ht.collectiontype == "已对账")
            //{
            //    if (ht.contractType == "产交合同")
            //    {
            //        sql = "insert into HT_SKXX( projectCode, collectionTime, CollectionAmount, collectionAccount, collectionBank, collectionName, payAccount, payBank, payAmount, infoType,xmbh,serialNumber,paytime,planid,collectiontype,username,invoiceType,invoicingType,invoiceID)" +
            //            " values ( '" + ht.projectCode + "','" + ht.collectionTime + "'," + ht.CollectionAmount + ",'" + ht.collectionAccount + "','" + ht.collectionBank + "','" + ht.collectionName + "','" +
            //            ht.payAccount + "','" + ht.payBank + "'," + ht.payAmount + ",'" + ht.infoType + "','" + ht.keyStr + "','" + ht.serialNumber + "','" + ht.paytime + "','" + ht.planid + "','" + ht.collectiontype + "','" + ht.username + "','" + ht.invoiceType + "','" + ht.invoicingType + "','" + ht.invoiceID + "') ;  ";
            //        sql += "delete HT_AssetsZF where xmbh='" + ht.keyStr + "'; ";
            //        //  sql += "insert into HT_AssetsZF(HTBH, XMBH, zfje) values('"+ht.projectCode+"','"+ht.xmbh+ "'," + ht.CollectionAmount + "/100) ; ";
            //        sql += "insert into HT_AssetsZF(HTBH, XMBH, zfje) select '" + ht.projectCode + "','" + ht.keyStr + "',sum(isnull(CollectionAmount,0)) from HT_SKXX where xmbh='" + ht.keyStr + "'; ";


            //    }
            //    else
            //    {
            //        sql = "insert into HT_SKXX( projectCode, collectionTime, CollectionAmount, collectionAccount, collectionBank, collectionName, payAccount, payBank, payAmount, infoType,xmbh,serialNumber,paytime,planid,collectiontype,username,invoiceType,invoicingType,invoiceID)" +
            //            " values ( '" + ht.projectCode + "','" + ht.collectionTime + "'," + ht.CollectionAmount + ",'" + ht.collectionAccount + "','" + ht.collectionBank + "','" + ht.collectionName + "','" +
            //            ht.payAccount + "','" + ht.payBank + "'," + ht.payAmount + ",'" + ht.infoType + "','','" + ht.serialNumber + "','" + ht.paytime + "','" + ht.planid + "','" + ht.collectiontype + "','" + ht.username + "','" + ht.invoiceType + "','" + ht.invoicingType + "','" + ht.invoiceID + "') ;  ";

            //    }
            //}
            //else if (ht.collectiontype == "已对帐")
            //{
            //    sql = "update HT_SKXX set collectionTime='" + ht.collectionTime + "',CollectionAmount='" + ht.CollectionAmount + "', collectionAccount='" + ht.collectionAccount + "', collectionBank='" + ht.collectionBank
            //        + "', collectionName='" + ht.collectionName + "', payAccount='" + ht.payAccount + "', payBank='" + ht.payBank + "' where serialNumber='" + ht.serialNumber + "'";
            //}
            else if (ht.collectiontype == "对账取消")
            {
                //sql = @"update HT_SKXX set collectionTime=NULL,CollectionAmount=NULL, collectionAccount=NULL, collectionBank=NULL"
                //        + ", collectionName=NULL, payAccount=NULL, payBank=NULL where serialNumber='" + ht.serialNumber + "'";
                sql = "delete from HT_SKXX where serialNumber='" + ht.serialNumber + "' and collectiontype='已对账' and planid='" + ht.planid + "' and invoiceID='" + ht.invoiceID + "'";
            }
            if (ht.contractType == "租赁合同")
            {
                sql += "update ht_zlht set zfje=(select sum(isnull(CollectionAmount,0)) from HT_SKXX where htbh='" + ht.projectCode + "'  and invoicingtype<>'结算单') where htbh='" + ht.projectCode + "'; ";
            }
            if (ht.contractType == "通用收款合同")
            {
                sql += "update ht_tyskht set zfje=(select sum(isnull(CollectionAmount,0)) from HT_SKXX where htbh='" + ht.projectCode + "'  and invoicingtype<>'结算单') where htbh='" + ht.projectCode + "'; ";
            }
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }



        #endregion

        #region "租赁合同保底租金"
        public static async Task<DataTable> GetHT_ZLHT_BDZJ(string htbh, string bgdh)
        {
            string sql = "";
            if(bgdh != "" && bgdh != null)
            {
                sql = "select * from ht_ZLHT_BDZJ_bgd where htbh='" + htbh + "' and bgdh='" + bgdh + "' ;";

            }
            else 
            {
                sql = "select * from ht_ZLHT_BDZJ where htbh='" + htbh + "' ;";

            }




            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> DeleteHT_ZLHT_BDZJ(string htbh)
        {


            string sql = "delete ht_ZLHT_BDZJ where htbh='" + htbh + "';";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> DeleteHT_ZLHT_BDZJ_BGD(string htbh,string bgdh )
        {


            string sql = "delete ht_ZLHT_BDZJ_BGD where htbh='" + htbh + "'  and bgdh='"+bgdh+"' ;";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> InsertHT_ZLHT_BDZJ(HT_ZLHT_BDZJ ht)
        {

            string sql = "";
            //if (ht.Listid == "")
            //{
                sql = "insert into ht_ZLHT_BDZJ(HTBH,BDZJ,GLF,zt,label) values ('" + ht.htbh + "','" + ht.bdzj + "','" + ht.glf + "','1','"+ht.label+"');";
            //}
            //else
            //{
            //    sql = "update ht_ZLHT_BDZJ set HTBH='" + ht.htbh + "',bdzj='" + ht.bdzj + "',glf='" + ht.glf + "',zt='" + ht.zt + "' where listid='" + ht.Listid + "' ";
            //}

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }



        #endregion
        #region"娄葑租赁合同附件"
        public static async Task<DataTable> DeleteHT_ZLHT_FILE(string htbh)
        {


            string sql = "delete HT_FILE where htbh='" + htbh + "'   ;";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> InsertHT_ZLHT_FILE(HT_FILE ht)
        {

            string sql = "";
            //if (ht.Listid == "")
            //{
            sql = "insert into HT_FILE(HTBH,filename,fileurl) values ('" + ht.htbh + "','" + ht.filename + "','" + ht.fileurl + "');";
            //}
            //else
            //{
            //    sql = "update ht_ZLHT_BDZJ set HTBH='" + ht.htbh + "',bdzj='" + ht.bdzj + "',glf='" + ht.glf + "',zt='" + ht.zt + "' where listid='" + ht.Listid + "' ";
            //}

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        #endregion
        #region "乙方信息"
        public static async Task<DataTable> GetHT_YFXX(string htbh, string bgdh)
        {
            string sql = "";
            if (bgdh != "" && bgdh != null)
            {
                sql = "select * from ht_yfxx_bgd where bgdh='" + bgdh + "'  ;";
            }
            else {
                sql = "select * from ht_yfxx where htbh='" + htbh + "'  ;";
            }
           


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> DeleteHT_YFXX(string htbh)
        {


            string sql = "delete ht_yfxx where htbh='" + htbh + "';";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> InsertHT_YFXX(HT_YFXX ht)
        {
            string sql = "";
          
                sql = "insert into HT_YFXX(HTBH, yfmc, yffrdb, yfdbry, yflxdh, yffdzd, yfyb, yfshxydm, yfsfzhm,zt) values ('" + ht.htbh + "', '" + ht.yfmc + "', '" + ht.yffrdb + "', '" + ht.yfdbry + "', '" + ht.yflxdh + "', '" + ht.yffdzd + "', '" + ht.yfyb + "', '" + ht.yfshxydm + "', '" + ht.yfsfzhm + "','1');";

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> DeleteHT_YFXX_BGD(string htbh,string bgdh)
        {


            string sql = "delete ht_yfxx_bgd where htbh='" + htbh + "' and bgdh='"+bgdh+"';";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> InsertHT_YFXX_BGD(HT_YFXX ht)
        {
            string sql = "";

            sql = "insert into HT_YFXX_bgd(HTBH, yfmc, yffrdb, yfdbry, yflxdh, yffdzd, yfyb, yfshxydm, yfsfzhm,zt,bgdh) values ('" + ht.htbh + "', '" + ht.yfmc + "', '" + ht.yffrdb + "', '" + ht.yfdbry + "', '" + ht.yflxdh + "', '" + ht.yffdzd + "', '" + ht.yfyb + "', '" + ht.yfshxydm + "', '" + ht.yfsfzhm + "','1','"+ht.bgdh+"');";

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        #endregion
        #region "资产信息"
        public static async Task<DataTable> GetHT_ZCXX(string htbh,string bgdh,string htlx)
        {
            string sql = "";
            if (htlx == "产交合同")
            {
                sql = "select  * from vw_ht_AssetsZC where xmbh='" + htbh + "' ;  ";
            }
            else
            {
                if (bgdh != "" && bgdh != null)
                {
                    sql = "select  a.HTBH,a.zcbw,a.mjsl,a.cjj,a.jgdw,a.jydw,a.zdj,b.* from HT_ZCXX_bgd a left join vw_ht_gjf b on a.zcbh=b.zcdm  where htbh='" + htbh + "' and bgdh='" + bgdh + "' ; ";

                }
                else
                {
                    sql = "select  a.HTBH,a.zcbw,a.mjsl,a.cjj,a.jgdw,a.jydw,a.zdj,b.* from HT_ZCXX a left join vw_ht_gjf b on a.zcbh=b.zcdm  where htbh='" + htbh + "' ; ";

                }
            }
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> GetHT_ZCXXx(string htbh, string bgdh, string htlx)
        {
            string sql = "";
            if (htlx == "产交合同")
            {
                sql = "select  * from vw_ht_AssetsZC where xmbh='" + htbh + "' ;  ";
            }
            else
            {
                if (bgdh != "" && bgdh != null)
                {
                    sql = "select  * from HT_ZCXX_bgd where htbh='" + htbh + "' and bgdh='" + bgdh + "' ; ";

                }
                else
                {
                    sql = "select  * from HT_ZCXX  where htbh='" + htbh + "' ; ";

                }
            }
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> DeleteHT_ZCXX(string htbh)
        {


            string sql = "delete ht_ZCXX where htbh='" + htbh + "';";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> DeleteHT_ZCXX_BGD(string htbh,string bgdh)
        {


            string sql = "delete ht_ZCXX_BGD where htbh='" + htbh + "' and bgdh='"+bgdh+"' ;";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task InsertHT_ZCXX(HT_ZCXX ht)
        {
            string sql = "";
            //if (ht.Listid == "")
            //{
            
            sql = "insert into HT_ZCXX(HTBH,zcbh,zcmc,zcbw,zclx,zcyt,jylx,ssdw,mjsl,cjj,jgdw,jydw,zdj) values ('"+ht.htbh+ "','" + ht.zcbh + "','" + ht.zcmc + "','" + ht.zcbw + "','" + ht.zclx + "','" + ht.zcyt + "','" + ht.jylx + "','" + ht.ssdw + "','" + ht.mjsl + "','"+ht.cjj+"','"+ht.jgdw+"','"+ht.jydw+"',"+ht.zdj+") ; ";
            //}
            //else
            //{
            //    sql = "update ht_BZJ set HTBH='" + ht.htbh + "',bzjje='" + ht.bzjje + "',bzjdzsj='" + ht.bzjdzsj + "',thje='" + ht.thje + "',thsj='" + ht.thsj + "',sfth='" + ht.sfth + "',zt='" + ht.zt + "',sjthsj='"+ht.sjthsj+"' where listid='" + ht.Listid + "'  ";
            //}

             await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }
        public static async Task UpdateHT_ZCXX(HT_ZCXX_Total ht)
        {
            await DeleteHT_ZCXX(ht.htbh);
            foreach (HT_ZCXX zcxx in ht.zcxx)
            {
                await InsertHT_ZCXX(zcxx);
            }

        }


        #endregion
   

        #region "产交合同附件"
        public static async Task<DataTable> GetHT_ContractFile(string xmbh)
        {
            string sql = "select * from vw_ht_ContractFile where projcode='"+xmbh+"' ; ";
            
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }


        #endregion
        #region"合同执行部门"
        public static async Task<DataTable> GetHT_HTZXBM(string htbh)
        {
            string sql = "";
            
                sql = "select * from ht_htzxbm where htbh='" + htbh + "'  ;";
         

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> DeleteHT_HTZXBM(string htbh)
        {


            string sql = "delete ht_htzxbm where htbh='" + htbh + "';";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> InsertHT_HTZXBM(HT_Htzxbm ht)
        {
            string sql = "";

            sql = "insert into ht_htzxbm(HTBH, deptid,type) values ('" + ht.htbh + "', '" + ht.deptid + "','"+ht.type+"');";
            
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> DeleteHT_HTZXBM_BGD(string htbh,string bgdh)
        {


            string sql = "delete ht_htzxbm_bgd where htbh='" + htbh + "' and bgdh='"+bgdh+"';";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> InsertHT_HTZXBM_BGD(HT_Htzxbm ht)
        {
            string sql = "";

            sql = "insert into ht_htzxbm_bgd(HTBH, deptid,type,bgdh) values ('" + ht.htbh + "', '" + ht.deptid + "','" + ht.type + "','"+ht.bgdh+"');";

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        #endregion
        #region "合同变更管理"

        //获取变更单
        public static async Task<(IEnumerable<dynamic>, int)> GetHT_BGD(HT_BGDQuerry querry)
        {
            string str = "and   1=1 ";
            if (!string.IsNullOrEmpty(querry.htbh) && querry.htbh != "string")
            {
                str += "and htbh like'%" + querry.htbh + "%'";
            }
            if (!string.IsNullOrEmpty(querry.bmdm) && querry.bmdm != "string")
            {
                str += "and bmdm='" + querry.bmdm + "'";
            }
            if (!string.IsNullOrEmpty(querry.bgdh) && querry.bgdh != "string")
            {
                str += "and bgdh='" + querry.bgdh + "'";
            }
            if (!string.IsNullOrEmpty(querry.htmc) && querry.htmc != "string")
            {
                str += " and htmc like '%" + querry.htmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.htlx) && querry.htlx != "string")
            {
                str += " and htlx='" + querry.htlx + "'";
            }
            if (!string.IsNullOrEmpty(querry.zt) && querry.zt != "string")
            {
                str += " and zt='" + querry.zt + "'";
            }
            if (querry.sqksrq != null && querry.sqjsrq != null)
            {
                if (querry.sqjsrq >= querry.sqksrq)
                {
                    str += " and (sqrq>='" + querry.sqksrq + "' and sqrq<='" + querry.sqjsrq + "')";
                }
            }

            string sql = @"select * from vw_ht_bgd where bmdm in " + querry.DepartID + str;
            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            // return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.PageSize, querry.Current);
            return await new RepositoryFactory().BaseRepository().FindList(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);

        }
        public static async Task<DataTable> GetHT_BGDDetail(string bgdh, string htlx)
        {
            string sql = "";
            if (htlx == "采购合同")
            {
                sql = "select * from HT_CGHT_BGD where  bgdh='" + bgdh + "'  ; ";
            }
            if (htlx == "项目合同")
            {
                sql = "select * from ht_xmht_BGD where bgdh='" + bgdh + "'  ; ";
            }
            if (htlx == "通用付款合同")
            {
                sql = "select * from ht_tyfkht_BGD where  bgdh='" + bgdh + "'  ; ";
            }
            if (htlx == "租赁合同")
            {
                sql = "select * from ht_ZLHT_BGD where bgdh='" + bgdh + "'  ; "; 
             
            }
            if (htlx == "通用收款合同")
            {
                sql = "select * from ht_tyskht_BGD where  bgdh='" + bgdh + "'  ; ";

            }


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }




        //采购合同变更
        public static async Task InsertHT_CGHT_BGD(HT_CGHT_Total bgd)
        {

            string sql = "";
            HT_CGHT cghtbgd = bgd.cght;
            if (cghtbgd.Listid == "")
            {
                sql = @"insert into ht_cght_bgd ( sqr, sqbm, sqrq, jfmc, jffrdb, jfdbry, jflxdh, jffdzd, jfyb, jfshxydm, jfsfzhm,
                      htmc, htbh, htqdrq, htje, htkssj, htjssj, jkfs, cfdd, htqddd, fkzytj, htgfzyyw, wyzr, qtsx, zt, bmdm, bgdh, cgptbm, bgsm,tjbmdm)
            values ('"+cghtbgd.sqr+"','"+cghtbgd. sqbm+"','"+cghtbgd. sqrq+"','"+cghtbgd. jfmc+"','"+cghtbgd. jffrdb+"','"+cghtbgd. jfdbry+"','"+cghtbgd. jflxdh+"','"+cghtbgd. jffdzd+"','"+cghtbgd. jfyb+"','"+cghtbgd. jfshxydm+"','"+cghtbgd. jfsfzhm+"','"+cghtbgd. htmc+"','"+cghtbgd. htbh+"','"+cghtbgd. htqdrq+"','"+cghtbgd. htje+"','"+cghtbgd. htkssj+"','"+cghtbgd. htjssj+"','"+cghtbgd. jkfs+"','"+cghtbgd. cfdd+"','"+cghtbgd. htqddd+"','"+cghtbgd. fkzytj+"','"+cghtbgd. htgfzyyw+"','"+cghtbgd. wyzr+"','"+cghtbgd. qtsx+"','1','"+cghtbgd. bmdm+"','"+cghtbgd. bgdh+"','"+cghtbgd. cgptbm+"','"+cghtbgd. bgsm+"','"+cghtbgd.tjbmdm+"') ; ";
              
                sql += "update HT_CGHT set zt='6'where htbh='" + cghtbgd.htbh + "' ; ";

                //sql += "update HT_BDWXX set zt='6' where htbh='" + cghtbgd.htbh + "'  ; ";
                //sql += "update ht_skzh set zt='6' where htbh='" + cghtbgd.htbh + "'  ; ";
                //sql += "update ht_fkjh set zt='6' where htbh='" + cghtbgd.htbh + "'  ; ";
                //sql += "update ht_bzj set zt='6' where htbh='" + cghtbgd.htbh + "'  ; ";
                //sql += "update ht_yfxx set zt='6' where htbh='" + cghtbgd.htbh + "'  ; ";
                await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            }
            else
            {
                sql = "update ht_cght_bgd set   sqr='" + cghtbgd.sqr + "',sqbm = '"+cghtbgd. sqbm+"', sqrq = '"+cghtbgd. sqrq+"', jfmc = '"+cghtbgd. jfmc+"', jffrdb = '"+cghtbgd. jffrdb+"', jfdbry = '"+cghtbgd. jfdbry+"', jflxdh = '"+cghtbgd. jflxdh+"', jffdzd = '"+cghtbgd. jffdzd+"', jfyb = '"+cghtbgd. jfyb+"', jfshxydm = '"+cghtbgd. jfshxydm+"', jfsfzhm = '"+cghtbgd. jfsfzhm+"', htmc = '"+cghtbgd. htmc+"', htqdrq = '"+cghtbgd. htqdrq+"', htje = '"+cghtbgd. htje+"', htkssj = '"+cghtbgd. htkssj+"', htjssj = '"+cghtbgd. htjssj+"', jkfs = '"+cghtbgd. jkfs+"', cfdd = '"+cghtbgd. cfdd+"', htqddd = '"+cghtbgd. htqddd+"',fkzytj = '"+cghtbgd. fkzytj+"', htgfzyyw = '"+cghtbgd. htgfzyyw+"',wyzr = '"+cghtbgd. wyzr+"',qtsx = '"+cghtbgd. qtsx+"',bmdm = '"+cghtbgd. bmdm+"',cgptbm = '"+cghtbgd. cgptbm+"',bgsm = '"+cghtbgd. bgsm+"' where listid ='" + cghtbgd.Listid + "' and htbh='"+cghtbgd.htbh+"' and bgdh='"+cghtbgd.bgdh+"' ; ";
                await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            }


            await DeleteHT_BDWXX_BGD(cghtbgd.htbh, cghtbgd.bgdh);
            foreach (HT_BDWXX bdwxx in bgd.bdwxx)
            {
                await InsertHT_BDWXX_BGD(bdwxx);
            }
            await DeleteHT_SKZH_BGD(cghtbgd.htbh, cghtbgd.bgdh);
            foreach (HT_SKZH skzh in bgd.skzh)
            {
                await InsertHT_SKZH_BGD(skzh);
            }
            await DeleteHT_FKJH_BGD(cghtbgd.htbh, cghtbgd.bgdh);
            foreach (HT_FKJH fkjh in bgd.fkjh)
            {
                await InsertHT_FKJH_BGD(fkjh);
            }
            //await DeleteHT_BZJ_BGD(cghtbgd.htbh, cghtbgd.bgdh);
            //foreach (HT_BZJ bzjbgd in bgd.bzj)
            //{
            //    await InsertHT_BZJ_BGD(bzjbgd);
            //}
            await DeleteHT_YFXX_BGD(cghtbgd.htbh, cghtbgd.bgdh);
            foreach (HT_YFXX yfxx in bgd.yfxx)
            {
                await InsertHT_YFXX_BGD(yfxx);
            }
        }

        //项目合同变更
        public static async Task InsertHT_XMHT_BGD(HT_XMHT_BGD bgd)
        {

            string sql = "";
            if (bgd.Listid == "")
            {
                sql = @"insert into HT_XMHT_BGD (sqr, sqbm, sqrq, bgdh, htmc, htbh, htqdrq, htje, htkssj, htjssj, jkfs, cfdd, htqddd, xmmc, bd, gspsje, kgrq, jgrq, yfk, xmjl, xmhtlx, zrqxq, fkzytj, htgfzyyw, wyzr, qtsx, bgsm,zt,zbcjdh,bmdm)
values('" + bgd.sqr + "','" + bgd.sqbm + "','" + bgd.sqrq + "','" + bgd.bgdh + "','" + bgd.htmc + "','" + bgd.htbh + "','" + bgd.htqdrq + "','" + bgd.htje + "','" + bgd.htkssj + "','" + bgd.htjssj + "','" + bgd.jkfs + "','" + bgd.cfdd + "','" + bgd.htqddd + "','" + bgd.xmmc + "','" + bgd.bd + "','" + bgd.gspsje + "','" + bgd.kgrq + "','" + bgd.jgrq + "','" + bgd.yfk + "','" + bgd.xmjl + "','" + bgd.xmhtlx + "','" + bgd.zrqxq + "','" + bgd.fkzytj + "','" + bgd.htgfzyyw + "','" + bgd.wyzr + "','" + bgd.qtsx + "','" + bgd.bgsm + "','1','"+bgd.zbcjdh + "','" + bgd.bmdm + "' );  ";

                sql += "update ht_xmht set zt='6' where htbh='" + bgd.htbh + "'  ;";
                sql += "update ht_skzh set zt='6' where htbh='" + bgd.htbh + "'  ; ";
                sql += "update ht_fkjh set zt='6' where htbh='" + bgd.htbh + "' ; ";
                sql += "update ht_bzj set zt='6' where htbh='" + bgd.htbh + "' ; ";
                sql += "update ht_yfxx set zt='6' where htbh='" + bgd.htbh + "'  ; ";

            }
            else
            {
                sql = "update ht_xmht_bgd set  sqr='" + bgd.sqr + "', sqbm='" + bgd.sqbm + "', sqrq='" + bgd.sqrq + "', bgdh='" + bgd.bgdh + "', htqdrq='" + bgd.htqdrq + "', htje='" + bgd.htje + "', htkssj='" + bgd.htkssj + "', htjssj='" + bgd.htjssj + "', jkfs='" + bgd.jkfs + "', cfdd='" + bgd.cfdd + "', htqddd='" + bgd.htqddd + "', xmmc='" + bgd.xmmc + "',bd='" + bgd.bd + "', gspsje='" + bgd.gspsje + "',kgrq='" + bgd.kgrq + "', jgrq='" + bgd.jgrq + "', yfk='" + bgd.yfk + "', xmjl='" + bgd.xmjl + "', xmhtlx='" + bgd.xmhtlx + "', zrqxq='" + bgd.zrqxq + "', fkzytj='" + bgd.fkzytj + "', htgfzyyw='" + bgd.htgfzyyw + "', wyzr='" + bgd.wyzr + "', qtsx='" + bgd.qtsx + "',bgsm='" + bgd.bgsm + "', zt='1' , htmc='" + bgd.htmc + "' , htbh='" + bgd.htbh + "',zbcjdh='"+bgd.zbcjdh + "',bmdm='" + bgd.bmdm + "'  where listid='" + bgd.Listid + "'	  ; ";

            }

            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }


        //通用付款合同变更
        public static async Task InsertHT_TYFKHT_BGD(HT_TYFKHT_Total bgd)
        {

            string sql = "";
            HT_TYFKHT tyfkhtbgd = bgd.tyfkht;
            if (tyfkhtbgd.Listid == "")
            {
                sql = @"insert into HT_tyfkht_bgd (sqr, sqbm, sqrq, jfmc, jffrdb, jfdbry, jflxdh, jffdzd, jfyb, jfshxydm, jfsfzhm, htmc, htbh, htqdrq, htje, htkssj, htjssj, jkfs, cfdd, htqddd, fkzytj, htgfzyyw, wyzr, qtsx, zt, bmdm, bgdh, cgptbm, bgsm,tjrq)
values('"+tyfkhtbgd.sqr+"','"+tyfkhtbgd. sqbm+"','"+tyfkhtbgd. sqrq+"','"+tyfkhtbgd. jfmc+"','"+tyfkhtbgd. jffrdb+"','"+tyfkhtbgd. jfdbry+"','"+tyfkhtbgd. jflxdh+"','"+tyfkhtbgd. jffdzd+"','"+tyfkhtbgd. jfyb+"','"+tyfkhtbgd. jfshxydm+"','"+tyfkhtbgd. jfsfzhm+"','"+tyfkhtbgd. htmc+"','"+tyfkhtbgd. htbh+"','"+tyfkhtbgd. htqdrq+"','"+tyfkhtbgd. htje+"','"+tyfkhtbgd. htkssj+"','"+tyfkhtbgd. htjssj+"','"+tyfkhtbgd. jkfs+"','"+tyfkhtbgd. cfdd+"','"+tyfkhtbgd. htqddd+"','"+tyfkhtbgd. fkzytj+"','"+tyfkhtbgd. htgfzyyw+"','"+tyfkhtbgd. wyzr+"','"+tyfkhtbgd. qtsx+"','1','"+tyfkhtbgd. bmdm+"','"+tyfkhtbgd. bgdh+"','"+tyfkhtbgd. cgptbm+"','"+tyfkhtbgd. bgsm+"','"+tyfkhtbgd.tjrq+"' );  ";

                sql += "update  ht_tyfkht set zt='6' where htbh='" + tyfkhtbgd.htbh + "'  ;";
                //sql += "update HT_BDWXX set zt='6' where htbh='" + tyfkhtbgd.htbh + "'  ; ";
                //sql += "update ht_skzh set zt='6' where htbh='" + tyfkhtbgd.htbh + "'  ; ";
                //sql += "update ht_fkjh set zt='6' where htbh='" + tyfkhtbgd.htbh + "'  ; ";
                //sql += "update ht_bzj set zt='6' where htbh='" + tyfkhtbgd.htbh + "'  ; ";
                //sql += "update ht_yfxx set zt='6' where htbh='" + tyfkhtbgd.htbh + "'  ; ";
                await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            }
            else
            {
                sql = @"update ht_tyfkht_bgd set  sqr='" + tyfkhtbgd.sqr + "', sqbm = '"+tyfkhtbgd. sqbm+"', sqrq = '"+tyfkhtbgd. sqrq+"', jfmc = '"+tyfkhtbgd. jfmc+"', jffrdb = '"+tyfkhtbgd. jffrdb+"', jfdbry = '"+tyfkhtbgd. jfdbry+"', jflxdh = '"+tyfkhtbgd. jflxdh+"', jffdzd = '"+tyfkhtbgd. jffdzd+"', jfyb = '"+tyfkhtbgd. jfyb+"', jfshxydm = '"+tyfkhtbgd. jfshxydm+"', jfsfzhm = '"+tyfkhtbgd. jfsfzhm+"', htmc = '"+tyfkhtbgd. htmc+"', htqdrq = '"+tyfkhtbgd. htqdrq+"', htje = '"+tyfkhtbgd. htje+"', htkssj = '"+tyfkhtbgd. htkssj+"', htjssj = '"+tyfkhtbgd. htjssj+"', jkfs = '"+tyfkhtbgd. jkfs+"', cfdd = '"+tyfkhtbgd. cfdd+"', htqddd = '"+tyfkhtbgd. htqddd+"', fkzytj = '"+tyfkhtbgd. fkzytj+"', htgfzyyw = '"+tyfkhtbgd. htgfzyyw+"', wyzr = '"+tyfkhtbgd. wyzr+"', qtsx = '"+tyfkhtbgd. qtsx+"', bmdm = '"+tyfkhtbgd. bmdm+"', cgptbm = '"+tyfkhtbgd. cgptbm+"', bgsm = '"+tyfkhtbgd. bgsm+"'  where listid ='" + tyfkhtbgd.Listid + "' and htbh='"+tyfkhtbgd.htbh+"' and bgdh='"+tyfkhtbgd.bgdh+"'  ; ";
                await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            }

          
            await DeleteHT_BDWXX_BGD(tyfkhtbgd.htbh, tyfkhtbgd.bgdh);
            foreach (HT_BDWXX bdwxx in bgd.bdwxx)
            {
                await InsertHT_BDWXX_BGD(bdwxx);
            }
            await DeleteHT_SKZH_BGD(tyfkhtbgd.htbh, tyfkhtbgd.bgdh);
            foreach (HT_SKZH skzh in bgd.skzh)
            {
                await InsertHT_SKZH_BGD(skzh);
            }
            await DeleteHT_FKJH_BGD(tyfkhtbgd.htbh, tyfkhtbgd.bgdh);
            foreach (HT_FKJH fkjh in bgd.fkjh)
            {
                await InsertHT_FKJH_BGD(fkjh);
            }
            //await DeleteHT_BZJ_BGD(tyfkhtbgd.htbh, tyfkhtbgd.bgdh);
            //foreach (HT_BZJ bzjbgd in bgd.bzj)
            //{
            //    await InsertHT_BZJ_BGD(bzjbgd);
            //}
            await DeleteHT_YFXX_BGD(tyfkhtbgd.htbh, tyfkhtbgd.bgdh);
            foreach (HT_YFXX yfxx in bgd.yfxx)
            {
                await InsertHT_YFXX_BGD(yfxx);
            }
        }

        //租赁合同变更
        public static async Task InsertHT_ZLHT_BGD(HT_ZLHT_BGD_Total bgd)
        {
            string sql = "";
            HT_ZLHT zlhtbgd = bgd.zlhtbgd;
            zlhtbgd.pgj=zlhtbgd.pgj==null?0: zlhtbgd.pgj;
            if (zlhtbgd.Listid == "")
            {
                 sql = @"delete from ht_zlht_BGD where bgdh='"+zlhtbgd.bgdh+ @"'; insert into ht_zlht_BGD ( htbh,bgdh,bgsm ,sqr, sqbm, sqrq, cqrmc, cqrhm, cqrfrdb, cqrdbry, cqrlxdh, cqrfdzd, cqryb, cqrshxydm, cqrsfzhm, czrmc, czrfrdb, czrdbry, czrlxdh, czrfdzd, czryb, czrshxydm, 
                      czrsfzhm, dgfmc, dgffrdb, dgfdbry, dgflxdh, dgffdzd, dgfyb, dgfshxydm, dgfsfzhm, xmmc, htmc, htlx, sfxz, htqdrq, htqdksrq, htqdjsrq, htqx, htqddd, cfdd, htsm, zlyt, htjzmj, htsymj, gtmj, czmj, zxkssj, 
                      zxjssj, zxqx, qqqmq, zlkssj, zljssj, zlq, zjfs, fkzq, sfrq, sfje, ck, yzj, ysdf, zzj, wyxz, ywyf, skqx, sz, pt, qt, skgz, tqjcx, htqd, tqjy, tqjch, xzx, wyj, jfwyj, yfwyj, bhtyts, jfz, yfz, bfz, zt, 
                     bmdm,czrzhbh,cqrkhh,cqryhzh,czrlx,czrhm,czrkhh,czryhzh,xmbh,zzjgdm,zzjgmc,cjrq,ptjybh,znjbl,jylx,yhtbh,pgj,tjr,tjbm,tjrq,tjbmdm,sssq,bz,kplx,sssqbm,zybm,qtsm,skfsx,cqrdm)
            values ('" + zlhtbgd.htbh + "','"+zlhtbgd.bgdh+"','"+zlhtbgd.bgsm+"','" + zlhtbgd.sqr + "','" + zlhtbgd.sqbm + "','" + zlhtbgd.sqrq + "','" + zlhtbgd.cqrmc + "','" + zlhtbgd.cqrhm + "','" + zlhtbgd.cqrfrdb + "','" + zlhtbgd.cqrdbry + "','" + zlhtbgd.cqrlxdh + "','" + zlhtbgd.cqrfdzd + "','" + zlhtbgd.cqryb + "','" + zlhtbgd.cqrshxydm + "','" + zlhtbgd.cqrsfzhm + "','" + zlhtbgd.czrmc + "','" + zlhtbgd.czrfrdb + "','" + zlhtbgd.czrdbry + "','" + zlhtbgd.czrlxdh + "','" + zlhtbgd.czrfdzd + "','" + zlhtbgd.czryb + "','" + zlhtbgd.czrshxydm + "','" + zlhtbgd.
                                  czrsfzhm + "','" + zlhtbgd.dgfmc + "','" + zlhtbgd.dgffrdb + "','" + zlhtbgd.dgfdbry + "','" + zlhtbgd.dgflxdh + "','" + zlhtbgd.dgffdzd + "','" + zlhtbgd.dgfyb + "','" + zlhtbgd.dgfshxydm + "','" + zlhtbgd.dgfsfzhm + "','" + zlhtbgd.xmmc + "','" + zlhtbgd.htmc + "','" + zlhtbgd.htlx + "','" + zlhtbgd.sfxz + "','" + zlhtbgd.htqdrq + "','" + zlhtbgd.htqdksrq + "','" + zlhtbgd.htqdjsrq + "','" + zlhtbgd.htqx + "','" + zlhtbgd.htqddd + "','" + zlhtbgd.cfdd + "','" + zlhtbgd.htsm + "','" + zlhtbgd.zlyt + "','" + zlhtbgd.htjzmj + "','" + zlhtbgd.htsymj + "','" + zlhtbgd.gtmj + "','" + zlhtbgd.czmj + "','" + zlhtbgd.zxkssj + "','" + zlhtbgd.
                                  zxjssj + "','" + zlhtbgd.zxqx + "','" + zlhtbgd.qqqmq + "','" + zlhtbgd.zlkssj + "','" + zlhtbgd.zljssj + "','" + zlhtbgd.zlq + "','" + zlhtbgd.zjfs + "','" + zlhtbgd.fkzq + "','" + zlhtbgd.sfrq + "','" + zlhtbgd.sfje + "','" + zlhtbgd.ck + "','" + zlhtbgd.yzj + "','" + zlhtbgd.ysdf + "','" + zlhtbgd.zzj + "','" + zlhtbgd.wyxz + "','" + zlhtbgd.ywyf + "','" + zlhtbgd.skqx + "','" + zlhtbgd.sz + "','" + zlhtbgd.pt + "','" + zlhtbgd.qt + "','" + zlhtbgd.skgz + "','" + zlhtbgd.tqjcx + "','" + zlhtbgd.htqd + "','" + zlhtbgd.tqjy + "','" + zlhtbgd.tqjch + "','" + zlhtbgd.xzx + "','" + zlhtbgd.wyj + "','" + zlhtbgd.jfwyj + "','" + zlhtbgd.yfwyj + "','" 
                                  + zlhtbgd.bhtyts + "','" + zlhtbgd.jfz + "','" + zlhtbgd.yfz + "','" + zlhtbgd.bfz + "','1','" + zlhtbgd.bmdm + "','"+zlhtbgd.czrzhbh+ "','" + zlhtbgd.cqrkhh + "','" 
                                  + zlhtbgd.cqryhzh + "','" + zlhtbgd.czrlx + "','" + zlhtbgd.czrhm + "','" + zlhtbgd.czrkhh + "','" + zlhtbgd.czryhzh + "','" + zlhtbgd.xmbh + "','" + zlhtbgd.zzjgdm 
                                  + "','" + zlhtbgd.zzjgmc + "','" + zlhtbgd.cjrq + "','" + zlhtbgd.ptjybh + "','" + zlhtbgd.znjbl + "','"+zlhtbgd.jylx+"','"+zlhtbgd.yhtbh+"',"+zlhtbgd.pgj+",'"+zlhtbgd.tjr
                                  +"','"+zlhtbgd.tjbm+"','"+zlhtbgd.tjrq+"','"+zlhtbgd.tjbmdm+"','"+zlhtbgd.sssq+"','"+zlhtbgd.bz+"','"+zlhtbgd.kplx+"','"+zlhtbgd.sssqbm+"','"+zlhtbgd.zybm+"','"+ zlhtbgd.qtsm + 
                                  "','"+zlhtbgd.skfsx + "','"+zlhtbgd.cqrdm+"'); ";
                
                sql += "update ht_zlht_bgd set htqdrq=null where htqdrq='1900-01-01 00:00:00.000' and bgdh='" + zlhtbgd.bgdh + "' ; ";
                sql += "update ht_zlht_bgd set htqdksrq=null where htqdksrq='1900-01-01 00:00:00.000' and bgdh='" + zlhtbgd.bgdh + "' ; ";
                sql += "update ht_zlht_bgd set htqdjsrq=null where htqdjsrq='1900-01-01 00:00:00.000' and bgdh='" + zlhtbgd.bgdh + "' ; ";
                sql += "update ht_zlht_bgd set zxkssj=null where zxkssj='1900-01-01 00:00:00.000' and bgdh='" + zlhtbgd.bgdh + "' ; ";
                sql += "update ht_zlht_bgd set zxjssj=null where zxjssj='1900-01-01 00:00:00.000' and bgdh='" + zlhtbgd.bgdh + "' ; ";
                sql += "update ht_zlht_bgd set zlkssj=null where zlkssj='1900-01-01 00:00:00.000' and bgdh='" + zlhtbgd.bgdh + "' ; ";
                sql += "update ht_zlht_bgd set zljssj=null where zljssj='1900-01-01 00:00:00.000' and bgdh='" + zlhtbgd.bgdh + "' ; ";
                sql += "update ht_zlht_bgd set sfrq=null where sfrq='1900-01-01 00:00:00.000' and bgdh='" + zlhtbgd.bgdh + "' ; ";

                sql += "update  ht_zlht set zt='6' where htbh='" + zlhtbgd.htbh + "'  ;";

                await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            }
            else
            {
                 sql = @"update ht_zlht_bgd set   bgsm='"+ zlhtbgd.bgsm+"', sqr='" + zlhtbgd.sqr + "',	 sqbm='" + zlhtbgd.sqbm + "',	 sqrq='" + zlhtbgd.sqrq + "',	 cqrmc='" + zlhtbgd.cqrmc + "',	 cqrhm='" + zlhtbgd.cqrhm + "',	" +
                    " cqrfrdb='" + zlhtbgd.cqrfrdb + "',	 cqrdbry='" + zlhtbgd.cqrdbry + "',	 cqrlxdh='" + zlhtbgd.cqrlxdh + "',	 cqrfdzd='" + zlhtbgd.cqrfdzd + "',	 cqryb='" + zlhtbgd.cqryb + "',	 cqrshxydm='" + zlhtbgd.cqrshxydm + "',	" +
                    " cqrsfzhm='" + zlhtbgd.cqrsfzhm + "',czrzhbh='"+zlhtbgd.czrzhbh+"',	 czrmc='" + zlhtbgd.czrmc + "',	 czrfrdb='" + zlhtbgd.czrfrdb + "',	 czrdbry='" + zlhtbgd.czrdbry + "',	 czrlxdh='" + zlhtbgd.czrlxdh + "',	 " +
                    "czrfdzd='" + zlhtbgd.czrfdzd + "',	 czryb='" + zlhtbgd.czryb + "',	 czrshxydm='" + zlhtbgd.czrshxydm + "',	 czrsfzhm='" + zlhtbgd.czrsfzhm + "',	 dgfmc='" + zlhtbgd.dgfmc + "',	 dgffrdb='" + zlhtbgd.dgffrdb + "',	" +
                    " dgfdbry='" + zlhtbgd.dgfdbry + "',	 dgflxdh='" + zlhtbgd.dgflxdh + "',	 dgffdzd='" + zlhtbgd.dgffdzd + "',	 dgfyb='" + zlhtbgd.dgfyb + "',	 dgfshxydm='" + zlhtbgd.dgfshxydm + "',	 dgfsfzhm='" + zlhtbgd.dgfsfzhm + "'," +
                    "	 xmmc='" + zlhtbgd.xmmc + "',	 htmc='" + zlhtbgd.htmc + "',	 htlx='" + zlhtbgd.htlx + "',	 sfxz='" + zlhtbgd.sfxz + "',	 htqdrq='" + zlhtbgd.htqdrq + "',	 htqdksrq='" + zlhtbgd.htqdksrq + "',	" +
                    " htqdjsrq='" + zlhtbgd.htqdjsrq + "',	 htqx='" + zlhtbgd.htqx + "',	 htqddd='" + zlhtbgd.htqddd + "',	 cfdd='" + zlhtbgd.cfdd + "',	 htsm='" + zlhtbgd.htsm + "',	 zlyt='" + zlhtbgd.zlyt + "',	" +
                    " htjzmj='" + zlhtbgd.htjzmj + "',	 htsymj='" + zlhtbgd.htsymj + "',	 gtmj='" + zlhtbgd.gtmj + "',	 czmj='" + zlhtbgd.czmj + "',	 zxkssj='" + zlhtbgd.zxkssj + "',	 zxjssj='" + zlhtbgd.zxjssj + "',	" +
                    " zxqx='" + zlhtbgd.zxqx + "',	 qqqmq='" + zlhtbgd.qqqmq + "',	 zlkssj='" + zlhtbgd.zlkssj + "',	 zljssj='" + zlhtbgd.zljssj + "',	 zlq='" + zlhtbgd.zlq + "',	 zjfs='" + zlhtbgd.zjfs + "',	" +
                    " fkzq='" + zlhtbgd.fkzq + "',	 sfrq='" + zlhtbgd.sfrq + "',	 sfje='" + zlhtbgd.sfje + "',	 ck='" + zlhtbgd.ck + "',	 yzj='" + zlhtbgd.yzj + "',	 ysdf='" + zlhtbgd.ysdf + "',	 zzj='" + zlhtbgd.zzj + "',	" +
                    " wyxz='" + zlhtbgd.wyxz + "',	 ywyf='" + zlhtbgd.ywyf + "',	 skqx='" + zlhtbgd.skqx + "',	 sz='" + zlhtbgd.sz + "',	 pt='" + zlhtbgd.pt + "',	 qt='" + zlhtbgd.qt + "',	 skgz='" + zlhtbgd.skgz + "',	" +
                    " tqjcx='" + zlhtbgd.tqjcx + "',	 htqd='" + zlhtbgd.htqd + "',	 tqjy='" + zlhtbgd.tqjy + "',	 tqjch='" + zlhtbgd.tqjch + "',	 xzx='" + zlhtbgd.xzx + "',	 wyj='" + zlhtbgd.wyj + "',	 jfwyj='" + zlhtbgd.jfwyj + "'," +
                    "	 yfwyj='" + zlhtbgd.yfwyj + "',	 bhtyts='" + zlhtbgd.bhtyts + "',	 jfz='" + zlhtbgd.jfz + "',	 yfz='" + zlhtbgd.yfz + "',	 bfz='" + zlhtbgd.bfz + "',	 zt='" + zlhtbgd.zt + "',	 bmdm='" + zlhtbgd.bmdm + "'," +
                    "cqrkhh='" + zlhtbgd.cqrkhh + "',cqryhzh='" + zlhtbgd.cqryhzh + "',czrlx='" + zlhtbgd.czrlx + "',czrhm='" + zlhtbgd.czrhm + "',czrkhh='" + zlhtbgd.czrkhh + "',czryhzh='" + zlhtbgd.czryhzh + "',xmbh='" + zlhtbgd.xmbh + "'," +
                    "zzjgdm='" + zlhtbgd.zzjgdm + "',zzjgmc='" + zlhtbgd.zzjgmc + "',cjrq='" + zlhtbgd.cjrq + "',ptjybh='" + zlhtbgd.ptjybh + "',znjbl='" + zlhtbgd.znjbl + "',jylx='"+zlhtbgd.jylx+"',yhtbh='"+zlhtbgd.yhtbh+"'," +
                    "pgj="+zlhtbgd.pgj+",tjr='"+zlhtbgd.tjr+"',tjbm='"+zlhtbgd.tjbm+"',tjrq='"+zlhtbgd.tjrq+ "',tjbmdm='" + zlhtbgd.tjbmdm+ "',cqrdm='"+zlhtbgd.cqrdm+"'" +
                    " where listid='" + zlhtbgd.Listid + "' and htbh='" + zlhtbgd.htbh + "' and bgdh='"+ zlhtbgd.bgdh + "'	  ; ";

              await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            }
            await DeleteHT_ZCXX_BGD(zlhtbgd.htbh,zlhtbgd.bgdh);
            foreach (HT_ZCXX zcxxbgd in bgd.zcxxbgd)
            {
                await InsertHT_ZCXX_BGD(zcxxbgd);
            }
            await DeleteHT_BZJ_BGD(zlhtbgd.htbh, zlhtbgd.bgdh);
            foreach (HT_BZJ bzjbgd in bgd.bzjbgd)
            {
                await InsertHT_BZJ_BGD(bzjbgd);
            }
            await DeleteHT_ZLHT_BDZJ_BGD(zlhtbgd.htbh, zlhtbgd.bgdh);
            foreach (HT_ZLHT_BDZJ bdzjbgd in bgd.bdzjbgd)
            {
                await InsertHT_ZLHT_BDZJ_BGD(bdzjbgd);
            }
            await DeleteHT_SKJH_BGD(zlhtbgd.htbh, zlhtbgd.bgdh);
            foreach (HT_SKJH skjhbgd in bgd.skjhbgd)
            {
                if (string.IsNullOrEmpty(skjhbgd.bgdh))
                { 
                skjhbgd.bgdh = zlhtbgd.bgdh;
                }
                if (skjhbgd.Listid == 0)
                { 
                skjhbgd.Listid = await getskjhbgdmaxid();
                }
                await InsertHT_SKJH_BGD(skjhbgd);
            }
            if (bgd.yys != null)
            {
                await deleteht_yys_bgd(zlhtbgd.htbh, zlhtbgd.bgdh);
                foreach (ht_yys_bgd yys in bgd.yys)
                {
                    if (string.IsNullOrEmpty(yys.bgdh))
                    {
                        yys.bgdh = zlhtbgd.bgdh;
                    }
                    await insertht_yys_bgd(yys);
                }
            }
            if (bgd.srqrb != null)
            {
                await deleteht_srqkb_bgd(zlhtbgd.htbh, zlhtbgd.bgdh);
                foreach (ht_srqrb_bgd srqkb in bgd.srqrb)
                {
                    if (string.IsNullOrEmpty(srqkb.bgdh))
                    {
                        srqkb.bgdh = zlhtbgd.bgdh;
                    }
                    await insertht_srqkb_bgd(srqkb);
                }
            }
        }

        public static async Task<int> getskjhbgdmaxid()
        {
            string sql = "select max(listid) from ht_skjh_bgd";
           DataTable obj = await new RepositoryFactory().BaseRepository().FindTable(sql);
            if (obj.Rows[0][0] == DBNull.Value)
            {
                return 1;
            }
            else
            {
                return Convert.ToInt32(obj.Rows[0][0]) + 1;
            }
        }

        public static async Task deleteht_yys_bgd(string htbh,string bgdh)
        {
            string sql = "delete from ht_yys_bgd where htbh='"+htbh+"' and bgdh='"+bgdh+"'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }

        public static async Task insertht_yys_bgd(ht_yys_bgd bgd)
        {
            await new RepositoryFactory().BaseRepository().Insert(bgd);
        }

        public static async Task deleteht_srqkb_bgd(string htbh,string bgdh)
        {
            string sql = "delete from ht_srqrb_bgd where htbh='" + htbh + "' and bgdh='" + bgdh + "'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }

        public static async Task insertht_srqkb_bgd(ht_srqrb_bgd bgd)
        {
            await new RepositoryFactory().BaseRepository().Insert(bgd);
        }

        public static async Task<DataTable> InsertHT_SKJH_BGD(HT_SKJH ht)
        {

            string sql = "";
            //if (ht.Listid == "")
            //{
            sql = "insert into HT_SKJH_BGD(listid,htbh,bgdh,skfs,qs,jhskbl,jhskje,jhskrq,jhsknr,ssnd,skqj) values (" + ht.Listid+",'" + ht.htbh + "','"+ht.bgdh+"','" + ht.skfs + "','" + ht.qs + "','" + ht.jhskbl + "','" + ht.jhskje + "','" + ht.jhskrq + "','" + ht.jhsknr + "','"+ht.ssnd+"','"+ht.skqj+"') ; ";
            sql += "update HT_SKJH_BGD set jhskrq=null where jhskrq='1900-01-01 00:00:00.000' and htbh='" + ht.htbh + "' ; ";

            //}
            //else
            //{
            //    sql = "update HT_SKJH set HTBH='" + ht.htbh + "',jhnr='" + ht.jhnr + "',skbl='" + ht.skbl + "',skje='" + ht.skje + "',sksj='" + ht.sksj + "',sktj='" + ht.sktj + "',zt='" + ht.zt + "'  where listid='" + ht.Listid + "'  ";
            //}

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> InsertHT_BZJ_BGD(HT_BZJ ht)
        {
            if (ht.dzje == null)
            {
                ht.dzje = 0;
            }
          string  sql = "insert into ht_BZJ_bgd(HTBH,bgdh,bzjje,bzjdzsj,thje,thsj,sjthsj,sfth,zt,htlx,htmc,dzje) values ('" + ht.htbh + "','"+ht.bgdh+"','" + ht.bzjje + "','" + ht.bzjdzsj + "','" + ht.thje + "','" + ht.thsj + "','" + ht.sjthsj + "','" + ht.sfth + "','1','" + ht.htlx + "','" + ht.htmc + "','"+ht.dzje+"') ; ";
            sql += "update ht_BZJ_bgd set sjthsj=null where sjthsj='1900-01-01 00:00:00.000' and htbh='" + ht.htbh + "' and bgdh='"+ht.bgdh+"' ; ";
            sql += "update ht_BZJ_bgd set thsj=null where thsj='1900-01-01 00:00:00.000' and htbh='" + ht.htbh + "'  and bgdh='" + ht.bgdh + "'  ; ";
            sql += "update ht_BZJ_bgd set bzjdzsj=null where bzjdzsj='1900-01-01 00:00:00.000' and htbh='" + ht.htbh + "'  and bgdh='" + ht.bgdh + "'  ; ";

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> InsertHT_ZCXX_BGD(HT_ZCXX ht)
        {

            if (ht.zdj == null)
            {
                ht.zdj = 0;
            }
          String   sql = "insert into HT_ZCXX_BGD(HTBH,BGDH,zcbh,zcmc,zcbw,zclx,zcyt,jylx,ssdw,mjsl,cjj,jgdw,jydw,zdj) values ('" + ht.htbh + "','"+ht.bgdh+"','" + ht.zcbh + "','" + ht.zcmc + "','" + ht.zcbw + "','" + ht.zclx + "','" + ht.zcyt + "','" + ht.jylx + "','" + ht.ssdw + "','" + ht.mjsl + "','" + ht.cjj + "','"+ht.jgdw+"','"+ht.jydw+"',"+ht.zdj+") ; ";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> InsertHT_ZLHT_BDZJ_BGD(HT_ZLHT_BDZJ ht)
        {



            string sql = "insert into ht_ZLHT_BDZJ_bgd(HTBH,bgdh,bdzj,glf,zt) values ('" + ht.htbh + "','" + ht.bgdh + "','" + ht.bdzj + "','" + ht.glf + "','1');";

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }


        //通用收款合同变更
        public static async Task InsertHT_TYSKHT_BGD(HT_TYSKHT_Total bgd)
        {

            string sql = "";
            HT_TYSKHT tyskhtbgd = bgd.tyskht;
            if (tyskhtbgd.Listid == "")
            {
                sql = @"insert into HT_tyskht_bgd (sqr, sqbm, sqrq, jfmc, jffrdb, jfdbry, jflxdh, jffdzd, jfyb, jfshxydm, jfsfzhm,
                     htmc, htbh, htqdrq, htje, htkssj, htjssj, jkfs, cfdd, htqddd, fkzytj, htgfzyyw, wyzr, qtsx, zt, bmdm, bgdh, skgz, bgsm)
            values('" + tyskhtbgd.sqr + "','" + tyskhtbgd.sqbm + "','" + tyskhtbgd.sqrq + "','" + tyskhtbgd.jfmc + "','" + tyskhtbgd.jffrdb + "','" + tyskhtbgd.jfdbry + "','" + tyskhtbgd.jflxdh + "','" + tyskhtbgd.jffdzd + "','" + tyskhtbgd.jfyb + "','" + tyskhtbgd.jfshxydm + "','" + tyskhtbgd.jfsfzhm + "','" + tyskhtbgd.htmc + "','" + tyskhtbgd.htbh + "','" + tyskhtbgd.htqdrq + "','" + tyskhtbgd.htje + "','" + tyskhtbgd.htkssj + "','" + tyskhtbgd.htjssj + "','" + tyskhtbgd.jkfs + "','" + tyskhtbgd.cfdd + "','" + tyskhtbgd.htqddd + "','" + tyskhtbgd.fkzytj + "','" + tyskhtbgd.htgfzyyw + "','" + tyskhtbgd.wyzr + "','" + tyskhtbgd.qtsx + "','1','" + tyskhtbgd.bmdm + "','" + tyskhtbgd.bgdh + "','" + tyskhtbgd.skgz + "','" + tyskhtbgd.bgsm + "' );  ";

                sql += "update  ht_tyskht set zt='6' where htbh='" + tyskhtbgd.htbh + "'  ;";
                //sql += "update HT_BDWXX set zt='6' where htbh='" + tyskhtbgd.htbh + "'  ; ";

                //sql += "update ht_skjh set zt='6' where htbh='" + tyskhtbgd.htbh + "'  ; ";
                //sql += "update ht_bzj set zt='6' where htbh='" + tyskhtbgd.htbh + "'  ; ";
                //sql += "update ht_yfxx set zt='6' where htbh='" + tyskhtbgd.htbh + "'  ; ";
                await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            }
            else
            {
                sql = "update ht_tyskht_bgd set  sqr='" + tyskhtbgd.sqr + "',sqbm='" + tyskhtbgd.sqbm + "',sqrq='" + tyskhtbgd.sqrq + "',jfmc = '"+tyskhtbgd. jfmc+"',jffrdb='"+tyskhtbgd.jffrdb+"',jfdbry='"+tyskhtbgd.jfdbry+"',jflxdh='"+tyskhtbgd.jflxdh+"',jffdzd='"+tyskhtbgd.jffdzd+"',jfyb='"+tyskhtbgd.jfyb+"',jfshxydm='"+tyskhtbgd.jfshxydm+"',jfsfzhm='"+tyskhtbgd.jfsfzhm+"',htmc='"+tyskhtbgd.htmc+"',htqdrq='"+tyskhtbgd.htqdrq+"',htje='"+tyskhtbgd.htje+"',htkssj='"+tyskhtbgd.htkssj+"',htjssj='"+tyskhtbgd.htjssj+"',jkfs='"+tyskhtbgd.jkfs+"',cfdd='"+tyskhtbgd.cfdd+"',htqddd='"+tyskhtbgd.htqddd+"',fkzytj='"+tyskhtbgd.fkzytj+"',htgfzyyw='"+tyskhtbgd.htgfzyyw+"',wyzr='"+tyskhtbgd.wyzr+"',qtsx='"+tyskhtbgd.qtsx+"',bmdm='"+tyskhtbgd.bmdm+"',skgz='"+tyskhtbgd.skgz+"',bgsm='"+tyskhtbgd.bgsm+"' where listid='"+tyskhtbgd.Listid+"'and bgdh='"+tyskhtbgd.bgdh+"'and htbh='"+tyskhtbgd.htbh+"'	;";

                    await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            }
            await DeleteHT_BDWXX_BGD(tyskhtbgd.htbh, tyskhtbgd.bgdh);
            foreach (HT_BDWXX bdwxx in bgd.bdwxx)
            {
                await InsertHT_BDWXX_BGD(bdwxx);
            }
            //await DeleteHT_SKJH_BGD(tyskhtbgd.htbh, tyskhtbgd.bgdh);
            //foreach (HT_SKJH skjhbgd in bgd.skjh)
            //{
            //    await InsertHT_SKJH_BGD(skjhbgd);

            //}
            //await DeleteHT_BZJ_BGD(tyskhtbgd.htbh, tyskhtbgd.bgdh);
            //foreach (HT_BZJ bzjbgd in bgd.bzj)
            //{
            //    await InsertHT_BZJ_BGD(bzjbgd);
            //}
            await DeleteHT_YFXX_BGD(tyskhtbgd.htbh, tyskhtbgd.bgdh);
            foreach (HT_YFXX yfxx in bgd.yfxx)
            {
                await InsertHT_YFXX_BGD(yfxx);
            }


        }


        public static async Task<DataTable> DeleteHT_BGD(string htbh, string bgdh, string htlx)
        {

            string sql = "";
            if (htlx == "采购合同")
            {
                sql = "delete HT_CGHT_BGD where htbh='" + htbh + "' and bgdh='" + bgdh + "'  ; ";
                sql += "update HT_CGHT set zt='3' where htbh='" + htbh + "' ; ";
                sql += "update HT_BDWXX set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_skzh set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_fkjh set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_bzj set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_yfxx set zt='3' where htbh='" + htbh + "'  ; ";
            }
            if (htlx == "项目合同")
            {
                sql = "delete ht_xmht_BGD where htbh='" + htbh + "' and bgdh='" + bgdh + "'  ; ";
                sql += "update ht_xmht set zt='3' where htbh='" + htbh + "'  ;";
                sql += "update ht_skzh set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_fkjh set zt='3' where htbh='" + htbh + "' ; ";
                sql += "update ht_bzj set zt='3' where htbh='" + htbh + "' ; ";
                sql += "update ht_yfxx set zt='3' where htbh='" + htbh + "'  ; ";
            }
            if (htlx == "通用付款合同")
            {
                sql = "delete ht_tyfkht_BGD where htbh='" + htbh + "' and bgdh='" + bgdh + "'  ; ";
                sql += "update  ht_tyfkht set zt='3' where htbh='" + htbh + "'  ;";
                sql += "update HT_BDWXX set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_skzh set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_fkjh set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_bzj set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_yfxx set zt='3' where htbh='" + htbh + "'  ; ";
            }
            if (htlx == "租赁合同")
            {
                sql = "delete ht_zlht_BGD where htbh='" + htbh + "' and bgdh='" + bgdh + "'  ; ";
                sql += "delete ht_zcxx_bgd where htbh='" + htbh + "' and bgdh='" + bgdh + "'; ";
                sql += "delete ht_zlht_BDZJ_bgd where htbh='" + htbh + "' and bgdh='" + bgdh + "'; ";
                sql += "delete ht_BZJ_bgd where htbh='" + htbh + "' and bgdh='" + bgdh + "'; ";
                sql += "delete ht_SKJH_bgd where htbh='" + htbh + "' and bgdh='" + bgdh + "'; ";
                sql += "update HT_ZLHT set zt='3' where htbh='" + htbh + "'  ;";
                sql += "update ht_bzj set zt='3' where htbh='" + htbh + "'  ; ";
            }
            if (htlx == "通用收款合同")
            {
                sql = "delete  ht_tyskht_BGD where htbh='" + htbh + "' and bgdh='" + bgdh + "'  ; ";
                sql += "update  ht_tyskht set zt='3' where htbh='" + htbh + "'  ;";
                sql += "update HT_BDWXX set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_yfxx set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_skjh set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_bzj set zt='3' where htbh='" + htbh + "'  ; ";

            }


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> SubmitHT_BGD( string bgdh, string htlx)
        {

            string sql = "";
            if (htlx == "采购合同")
            {
                sql = "update HT_CGHT_BGD set zt='2' where  bgdh='" + bgdh + "'  ; ";
            }
            if (htlx == "项目合同")
            {
                sql = "update ht_xmht_BGD set zt='2' where bgdh='" + bgdh + "'  ; ";
            }
            if (htlx == "通用付款合同")
            {
                sql = "update ht_tyfkht_BGD set zt='2' where  bgdh='" + bgdh + "'  ; ";
            }
            if (htlx == "租赁合同")
            {
                sql = "update ht_zlht_BGD set zt='2' where  bgdh='" + bgdh + "'  ; ";
             
            }
            if (htlx == "通用收款合同")
            {
                sql = "update  ht_tyskht_BGD set zt='2' where  bgdh='" + bgdh + "'  ; ";

            }



            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

       public static async Task<DataTable> AuditHT_BGD(string htbh, string bgdh, string htlx)
        {

            string sql = "";
            if (htlx == "采购合同")
            {
               
                sql = @"insert into HT_CGHT_bak ( sqr, sqbm, sqrq, jfmc, jffrdb, jfdbry, jflxdh, jffdzd, jfyb, jfshxydm, jfsfzhm, yfmc, yffrdb, yfdbry, yflxdh, yffdzd, yfyb, yfshxydm, yfsfzhm, bfmc, bffrdb, bfdbry, bflxdh, bffdzd, 
                      bfyb, bfshxydm, bfsfzhm, htmc, htbh, htqdrq, htje, htkssj, htjssj, jkfs, cfdd, htqddd, fkzytj, htgfzyyw, wyzr, qtsx, zt,bmdm)
                      SELECT sqr, sqbm, sqrq, jfmc, jffrdb, jfdbry, jflxdh, jffdzd, jfyb, jfshxydm, jfsfzhm, yfmc, yffrdb, yfdbry, yflxdh, yffdzd, yfyb, yfshxydm, yfsfzhm, bfmc, bffrdb, bfdbry, bflxdh, bffdzd,
                      bfyb, bfshxydm, bfsfzhm, htmc, htbh, htqdrq, htje, htkssj, htjssj, jkfs, cfdd, htqddd, fkzytj, htgfzyyw, wyzr, qtsx, zt,bmdm
                       from HT_CGHT where htbh = '"+htbh+"' ; ";
                sql += @"update HT_CGHT
                       set HT_CGHT.sqr = b.sqr,
                       HT_CGHT.sqbm = b.sqbm,
                       HT_CGHT.sqrq = b.sqrq,
                      HT_CGHT.htmc = b.htmc,
                      HT_CGHT.htqdrq = b.htqdrq,
                      HT_CGHT.htje = b.htje,
                      HT_CGHT.htkssj = b.htkssj,
                      HT_CGHT.htjssj = b.htjssj,
                      HT_CGHT.jkfs = b.jkfs,
                      HT_CGHT.cfdd = b.cfdd,
                      HT_CGHT.htqddd = b.htqddd,
                      HT_CGHT.fkzytj = b.fkzytj,
                      HT_CGHT.htgfzyyw = b.htgfzyyw,
                      HT_CGHT.wyzr = b.wyzr,
                      HT_CGHT.qtsx = b.qtsx,
                      HT_CGHT.zt = '3',
                      HT_CGHT.bmdm = b.bmdm
                      from HT_CGHT a
                      inner join HT_CGHT_BGD b on a.htbh = '" + htbh+ "' and b.htbh = '" + htbh + "' and b.bgdh = '" + bgdh + "' ; ";
                sql += "update HT_CGHT_BGD set zt='3' where htbh='" + htbh + "' and bgdh='" + bgdh + "'  ; ";
                sql += "update HT_BDWXX set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_skzh set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_fkjh set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_bzj set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_yfxx set zt='3' where htbh='" + htbh + "'  ; ";

            }
            if (htlx == "项目合同")
            {
                sql = @"insert into HT_XMHT_bak ( sqr, sqbm, sqrq, jfmc, jffrdb, jfdbry, jflxdh, jffdzd, jfyb, jfshxydm, jfsfzhm, yfmc, yffrdb, yfdbry, yflxdh, yffdzd, yfyb, yfshxydm, yfsfzhm, bfmc, bffrdb, bfdbry, bflxdh, bffdzd, 
                      bfyb, bfshxydm, bfsfzhm, htmc, htbh, htqdrq, htje, htkssj, htjssj, jkfs, cfdd, htqddd, xmmc, bd, gspsje, kgrq, jgrq, yfk, xmjl, xmhtlx, zrqxq, fkzytj, htgfzyyw, wyzr, qtsx, zt,zbcjdh,bmdm)
                      SELECT sqr, sqbm, sqrq, jfmc, jffrdb, jfdbry, jflxdh, jffdzd, jfyb, jfshxydm, jfsfzhm, yfmc, yffrdb, yfdbry, yflxdh, yffdzd, yfyb, yfshxydm, yfsfzhm, bfmc, bffrdb, bfdbry, bflxdh, bffdzd,
                      bfyb, bfshxydm, bfsfzhm, htmc, htbh, htqdrq, htje, htkssj, htjssj, jkfs, cfdd, htqddd, xmmc, bd, gspsje, kgrq, jgrq, yfk, xmjl, xmhtlx, zrqxq, fkzytj, htgfzyyw, wyzr, qtsx, zt,zbcjdh,bmdm
                       from HT_XMHT
                       where htbh = '" + htbh+"'; ";
                sql += @"update HT_XMHT 
                       set HT_XMHT. sqr=b. sqr,
                       HT_XMHT. sqbm=b. sqbm,
                       HT_XMHT. sqrq=b. sqrq,
                       HT_XMHT. htmc=b. htmc,
                       HT_XMHT. htqdrq=b. htqdrq,
                       HT_XMHT. htje=b. htje,
                       HT_XMHT. htkssj=b. htkssj,
                       HT_XMHT. htjssj=b. htjssj,
                       HT_XMHT. jkfs=b. jkfs,
                       HT_XMHT. cfdd=b. cfdd,
                       HT_XMHT. htqddd=b. htqddd,
                       HT_XMHT. xmmc=b. xmmc,
                       HT_XMHT. bd=b. bd,
                       HT_XMHT. gspsje=b. gspsje,
                       HT_XMHT. kgrq=b. kgrq,
                       HT_XMHT. jgrq=b. jgrq,
                       HT_XMHT. yfk=b. yfk,
                       HT_XMHT. xmjl=b. xmjl,
                       HT_XMHT. xmhtlx=b. xmhtlx,
                       HT_XMHT. zrqxq=b. zrqxq,
                       HT_XMHT. fkzytj=b. fkzytj,
                       HT_XMHT. htgfzyyw=b. htgfzyyw,
                       HT_XMHT. wyzr=b. wyzr,
                       HT_XMHT. qtsx=b. qtsx,
                       HT_XMHT.zt='3',
                       HT_XMHT.zbcjdh=b.zbcjdh,
                       HT_XMHT.bmdm=b.bmdm
                       from HT_XMHT a
                       inner join HT_XMHT_BGD b
                       on a.htbh='" + htbh+"' and b.htbh='"+htbh+"' and b.bgdh='"+bgdh+"' ; ";
                sql += "update ht_xmht_BGD set zt='3' where htbh='" + htbh + "' and bgdh='" + bgdh + "'  ; ";
                sql += "update ht_skzh set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_fkjh set zt='3' where htbh='" + htbh + "' ; ";
                sql += "update ht_bzj set zt='3' where htbh='" + htbh + "' ; ";
                sql += "update ht_yfxx set zt='3' where htbh='" + htbh + "'  ; ";

            }
            if (htlx == "通用付款合同")
            {
                sql = @"  insert into  HT_TYFKHT_BAK (sqr, sqbm, sqrq, jfmc, jffrdb, jfdbry, jflxdh, jffdzd, jfyb, jfshxydm, jfsfzhm, yfmc, yffrdb, yfdbry, yflxdh, yffdzd, yfyb, yfshxydm, yfsfzhm, bfmc, bffrdb, bfdbry, bflxdh, bffdzd, 
                      bfyb, bfshxydm, bfsfzhm, htmc, htbh, htqdrq, htje, htkssj, htjssj, jkfs, cfdd, htqddd, fkzytj, htgfzyyw, wyzr, qtsx, zt,bmdm)
                      SELECT  sqr, sqbm, sqrq, jfmc, jffrdb, jfdbry, jflxdh, jffdzd, jfyb, jfshxydm, jfsfzhm, yfmc, yffrdb, yfdbry, yflxdh, yffdzd, yfyb, yfshxydm, yfsfzhm, bfmc, bffrdb, bfdbry, bflxdh, bffdzd, 
                      bfyb, bfshxydm, bfsfzhm, htmc, htbh, htqdrq, htje, htkssj, htjssj, jkfs, cfdd, htqddd, fkzytj, htgfzyyw, wyzr, qtsx, zt,bmdm
                      from  HT_TYFKHT where htbh='"+htbh+"' ; ";
                sql += @" update HT_TYFKHT 
                      set HT_TYFKHT. sqr=b. sqr,
                      HT_TYFKHT. sqbm=b. sqbm,
                      HT_TYFKHT. sqrq=b. sqrq,
                      HT_TYFKHT. htmc=b. htmc,
                      HT_TYFKHT. htqdrq=b. htqdrq,
                      HT_TYFKHT. htje=b. htje,
                      HT_TYFKHT. htkssj=b. htkssj,
                      HT_TYFKHT. htjssj=b. htjssj,
                      HT_TYFKHT. jkfs=b. jkfs,
                      HT_TYFKHT. cfdd=b. cfdd,
                      HT_TYFKHT. htqddd=b. htqddd,
                      HT_TYFKHT. fkzytj=b. fkzytj,
                      HT_TYFKHT. htgfzyyw=b. htgfzyyw,
                      HT_TYFKHT. wyzr=b. wyzr,
                      HT_TYFKHT. qtsx=b. qtsx,
                      HT_TYFKHT. zt='3',
                       HT_TYFKHT. bmdm=b. bmdm
                      from HT_TYFKHT a
                      inner join HT_TYFKHT_BGD b
                        on a.htbh='" + htbh + "' and b.htbh='" + htbh + "' and b.bgdh='" + bgdh + "' ; ";
                sql = "update ht_tyfkht_BGD set zt='3' where htbh='" + htbh + "' and bgdh='" + bgdh + "'  ; ";
                sql += "update HT_BDWXX set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_skzh set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_fkjh set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_bzj set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_yfxx set zt='3' where htbh='" + htbh + "'  ; ";
            }
            if (htlx == "租赁合同")
            {
                sql = @"insert into  HT_ZLHT_BAK ( sqr, sqbm, sqrq, cqrmc, cqrfrdb, cqrdbry, cqrlxdh, cqrfdzd, cqryb, cqrshxydm, cqrsfzhm, czrmc, czrfrdb, czrdbry, czrlxdh, czrfdzd, czryb, czrshxydm, czrsfzhm, dgfmc, 
                      dgffrdb, dgfdbry, dgflxdh, dgffdzd, dgfyb, dgfshxydm, dgfsfzhm, jyxzc, jyxlx, htbh, htqdrq, cfdd, htqddd, xmmc, htmc, zlyt, zlkssj, zljssj, fkzq, czmj, lzmj, gtmj, sfrq, qqqm, zjfs, zzj, ck, zlq, zxqx, zxkssj, zxjssj, sz, ptss, qt, tqjcx, htqd, tqjy, tqjch, xzx, wyj, jfwyj, yfwyj, bhtyts, jfz, yfz, bfz, zt,bmdm)
                      SELECT   sqr, sqbm, sqrq, cqrmc, cqrfrdb, cqrdbry, cqrlxdh, cqrfdzd, cqryb, cqrshxydm, cqrsfzhm, czrmc, czrfrdb, czrdbry, czrlxdh, czrfdzd, czryb, czrshxydm, czrsfzhm, dgfmc, 
                      dgffrdb, dgfdbry, dgflxdh, dgffdzd, dgfyb, dgfshxydm, dgfsfzhm, jyxzc, jyxlx, htbh, htqdrq, cfdd, htqddd, xmmc, htmc, zlyt, zlkssj, zljssj, fkzq, czmj, lzmj, gtmj, sfrq, qqqm, zjfs, zzj, ck, zlq, zxqx, zxkssj, zxjssj, sz, ptss, qt, tqjcx, htqd, tqjy, tqjch, xzx, wyj, jfwyj, yfwyj, bhtyts, jfz, yfz, bfz, zt,bmdm
                      from  HT_ZLHT where htbh='"+htbh+"'; " ;
                sql += @" update HT_ZLHT 
                      set HT_ZLHT.sqr=b.sqr,
                      HT_ZLHT. sqbm=b. sqbm,
                      HT_ZLHT. sqrq=b. sqrq,
                      HT_ZLHT. jyxzc=b. jyxzc,
                      HT_ZLHT. jyxlx=b. jyxlx,
                      HT_ZLHT. htqdrq=b. htqdrq,
                      HT_ZLHT. cfdd=b. cfdd,
                      HT_ZLHT. htqddd=b. htqddd,
                      HT_ZLHT. xmmc=b. xmmc,
                      HT_ZLHT. htmc=b. htmc,
                      HT_ZLHT. zlyt=b. zlyt,
                      HT_ZLHT. zlkssj=b. zlkssj,
                      HT_ZLHT. zljssj=b. zljssj,
                      HT_ZLHT. fkzq=b. fkzq,HT_ZLHT. czmj=b. czmj,HT_ZLHT. lzmj=b. lzmj,HT_ZLHT. gtmj=b. gtmj,HT_ZLHT. sfrq=b. sfrq,HT_ZLHT. qqqm=b. qqqm,HT_ZLHT. zjfs=b. zjfs,HT_ZLHT. zzj=b. zzj,HT_ZLHT. ck=b. ck ,HT_ZLHT. zlq=b. zlq,
                      HT_ZLHT. zxqx=b. zxqx,
                      HT_ZLHT. zxkssj=b. zxkssj,
                      HT_ZLHT. zxjssj=b. zxjssj,
                      HT_ZLHT. sz=b. sz,
                      HT_ZLHT. ptss=b. ptss,
                      HT_ZLHT. qt=b. qt,
                      HT_ZLHT. tqjcx=b. tqjcx,
                      HT_ZLHT. htqd=b. htqd,HT_ZLHT. tqjy=b. tqjy,HT_ZLHT. tqjch=b. tqjch,
                      HT_ZLHT. xzx=b. xzx,
                      HT_ZLHT. wyj=b. wyj,
                      HT_ZLHT. jfwyj=b. jfwyj,
                      HT_ZLHT. yfwyj=b. yfwyj,
                      HT_ZLHT. bhtyts=b. bhtyts,
                      HT_ZLHT. jfz=b. jfz,
                      HT_ZLHT. yfz=b. yfz,
                      HT_ZLHT. bfz=b. bfz,
                      HT_ZLHT. zt='3',
                      HT_ZLHT. bmdm=b. bmdm
                      from HT_ZLHT a
                      inner join HT_ZLHT_BGD b
                      on a.htbh='" + htbh + "' and b.htbh='" + htbh + "' and b.bgdh='" + bgdh + "' ; ";
                sql += "delete ht_zlht_jbxx where htbh='" + htbh + "'; " ;
                sql += " insert into ht_ZLHT_JBXX(HTBH,bwmc,mj,zt) select HTBH, bwmc, mj, '3' from HT_ZLHT_JBXX_BGD where htbh='" + htbh + "' ; ";

                sql += "delete ht_zlht_bdzj where htbh='" + htbh + "'; ";
                sql += " insert into ht_ZLHT_bdzj(HTBH,bdzj,glf,zt) select HTBH, bdzj, glf, '3' from HT_ZLHT_bdzj_BGD where htbh='" + htbh + "' ; ";

                sql += "update ht_zlht_BGD set zt='3' where htbh='" + htbh + "' and bgdh='" + bgdh + "'  ; ";
       
                sql += "update ht_bzj set zt='3' where htbh='" + htbh + "'  ; ";
            }
            if (htlx == "通用收款合同")
            {
                sql = @"  insert into    HT_TYSKHT_BAK ( sqr, sqbm, sqrq, jfmc, jffrdb, jfdbry, jflxdh, jffdzd, jfyb, jfshxydm, jfsfzhm, yfmc, yffrdb, yfdbry, yflxdh, yffdzd, yfyb, yfshxydm, yfsfzhm, bfmc, bffrdb, bfdbry, bflxdh, bffdzd, 
                      bfyb, bfshxydm, bfsfzhm, htmc, htbh, htqdrq, htje, htkssj, htjssj, jkfs, cfdd, htqddd, fkzytj, htgfzyyw, wyzr, qtsx, zt,bmdm)
                      SELECT   sqr, sqbm, sqrq, jfmc, jffrdb, jfdbry, jflxdh, jffdzd, jfyb, jfshxydm, jfsfzhm, yfmc, yffrdb, yfdbry, yflxdh, yffdzd, yfyb, yfshxydm, yfsfzhm, bfmc, bffrdb, bfdbry, bflxdh, bffdzd, 
                      bfyb, bfshxydm, bfsfzhm, htmc, htbh, htqdrq, htje, htkssj, htjssj, jkfs, cfdd, htqddd, fkzytj, htgfzyyw, wyzr, qtsx, zt,bmdm
                      from    HT_TYSKHT where htbh='"+htbh+"'; ";
                sql += @"update HT_TYSKHT 
                      set HT_TYSKHT. sqr = b.sqr,
                      HT_TYSKHT.sqbm = b.sqbm,
                      HT_TYSKHT.sqrq = b.sqrq,

                      HT_TYSKHT.htmc = b.htmc,

                      HT_TYSKHT.htqdrq = b.htqdrq,
                      HT_TYSKHT.htje = b.htje,HT_TYSKHT.htkssj = b.htkssj,HT_TYSKHT.htjssj = b.htjssj,HT_TYSKHT.jkfs = b.jkfs,HT_TYSKHT.cfdd = b.cfdd,HT_TYSKHT.htqddd = b.htqddd,HT_TYSKHT.fkzytj = b.fkzytj,HT_TYSKHT.htgfzyyw = b.htgfzyyw,HT_TYSKHT.wyzr = b.wyzr,HT_TYSKHT.qtsx = b.qtsx,HT_TYSKHT.zt = '3',HT_TYSKHT.bmdm = b.bmdm
                               from HT_TYSKHT a
                      inner
                               join HT_TYSKHT_BGD b

                      on a.htbh='" + htbh + "' and b.htbh='" + htbh + "' and b.bgdh='" + bgdh + "' ; ";
                sql += "update  ht_tyfkht_BGD set zt='3' where htbh='" + htbh + "' and bgdh='" + bgdh + "'  ; ";
                sql += "update HT_BDWXX set zt='3' where htbh='" + htbh + "'  ; ";

                sql += "update ht_skjh set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_bzj set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_yfxx set zt='3' where htbh='" + htbh + "'  ; ";

            }
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> BackHT_BGD(string htbh, string bgdh, string htlx)
        {

            string sql = "";
            if (htlx == "采购合同")
            {
                sql = "update HT_CGHT_BGD set zt='4' where htbh='" + htbh + "' and bgdh='" + bgdh + "'  ; ";
            }
            if (htlx == "项目合同")
            {
                sql = "update ht_xmht_BGD set zt='4' where htbh='" + htbh + "' and bgdh='" + bgdh + "'  ; ";
            }
            if (htlx == "通用付款合同")
            {
                sql = "update ht_tyfkht_BGD set zt='4' where htbh='" + htbh + "' and bgdh='" + bgdh + "'  ; ";
            }
            if (htlx == "租赁合同")
            {
                sql = "update ht_tyfkht_BGD set zt='4' where htbh='" + htbh + "' and bgdh='" + bgdh + "'  ; ";
                sql += "update ht_zlht_jbxx_bgd set zt='4' where htbh='" + htbh + "' and bgdh='" + bgdh + "'; ";
            }
            if (htlx == "通用收款合同")
            {
                sql = "update  ht_tyfkht_BGD set zt='4' where htbh='" + htbh + "' and bgdh='" + bgdh + "'  ; ";

            }
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> StopHT_BGD(string htbh, string bgdh, string htlx)
        {

            string sql = "";
            if (htlx == "采购合同")
            {
                sql = "update HT_CGHT_BGD set zt='5' where htbh='" + htbh + "' and bgdh='" + bgdh + "'  ; ";
                sql += "update HT_CGHT set zt='3' where htbh='" + htbh + "' ; ";
                sql += "update HT_BDWXX set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_skzh set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_fkjh set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_bzj set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_yfxx set zt='3' where htbh='" + htbh + "'  ; ";
            }
            if (htlx == "项目合同")
            {
                sql = "update ht_xmht_BGD set zt='5' where htbh='" + htbh + "' and bgdh='" + bgdh + "'  ; ";
                sql += "update ht_xmht set zt='3' where htbh='" + htbh + "'  ;";
                sql += "update ht_skzh set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_fkjh set zt='3' where htbh='" + htbh + "' ; ";
                sql += "update ht_bzj set zt='3' where htbh='" + htbh + "' ; ";
                sql += "update ht_yfxx set zt='3' where htbh='" + htbh + "'  ; ";
            }
            if (htlx == "通用付款合同")
            {
                sql = "update ht_tyfkht_BGD set zt='5' where htbh='" + htbh + "' and bgdh='" + bgdh + "'  ; ";
                sql += "update  ht_tyfkht set zt='3' where htbh='" + htbh + "'  ;";
                sql += "update HT_BDWXX set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_skzh set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_fkjh set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_bzj set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_yfxx set zt='3' where htbh='" + htbh + "'  ; ";
            }
            if (htlx == "租赁合同")
            {
                sql = "update ht_tyfkht_BGD set zt='5' where htbh='" + htbh + "' and bgdh='" + bgdh + "'  ; ";
                sql += "update ht_zlht_jbxx_bgd set zt='5' where htbh='" + htbh + "' and bgdh='" + bgdh + "'; ";
                sql += "update HT_ZLHT set zt='3' where htbh='" + htbh + "'  ;";
                sql += "update HT_ZLHT_JBXX set zt='3' where htbh='" + htbh + "'  ; ";

                sql += "update ht_bzj set zt='3' where htbh='" + htbh + "'  ; ";
            }
            if (htlx == "通用收款合同")
            {
                sql = "update  ht_tyfkht_BGD set zt='5' where htbh='" + htbh + "' and bgdh='" + bgdh + "'  ; ";
                sql += "update  ht_tyskht set zt='3' where htbh='" + htbh + "'  ;";
                sql += "update HT_BDWXX set zt='3' where htbh='" + htbh + "'  ; ";

                sql += "update ht_skjh set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_bzj set zt='3' where htbh='" + htbh + "'  ; ";
                sql += "update ht_yfxx set zt='3' where htbh='" + htbh + "'  ; ";

            }


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

       


        public static async Task<DataTable> UpdateHT_BGDZT(string bgdh, string htlx, string zt)
        {

            string sql = "";
            if (zt == "3")
            {
                if (htlx == "采购合同")
                {
                    sql += "update ht_cght_bgd set zt='3'  where bgdh='" + bgdh + "' ; ";
                    sql += "delete ht_cght where htbh=(select HTBH from ht_cght_BGD where bgdh='" + bgdh + "' ) ; ";
                    sql += @"insert into HT_CGHT ( sqr, sqbm, sqrq, jfmc, jffrdb, jfdbry, jflxdh, jffdzd, jfyb, jfshxydm, jfsfzhm, yfmc, yffrdb, yfdbry, yflxdh, yffdzd, yfyb, yfshxydm, yfsfzhm, bfmc, bffrdb, bfdbry, bflxdh, bffdzd, 
                       bfyb, bfshxydm, bfsfzhm, htmc, htbh, htqdrq, htje, htkssj, htjssj, jkfs, cfdd, htqddd, fkzytj, htgfzyyw, wyzr, qtsx, zt, bmdm, zfje, bgdh, cgptbm)
                        select  sqr, sqbm, sqrq, jfmc, jffrdb, jfdbry, jflxdh, jffdzd, jfyb, jfshxydm, jfsfzhm, yfmc, yffrdb, yfdbry, yflxdh, yffdzd, yfyb, yfshxydm, yfsfzhm, bfmc, bffrdb, bfdbry, bflxdh, bffdzd, 
                      bfyb, bfshxydm, bfsfzhm, htmc, htbh, htqdrq, htje, htkssj, htjssj, jkfs, cfdd, htqddd, fkzytj, htgfzyyw, wyzr, qtsx, zt, bmdm, zfje, bgdh, cgptbm
                       from HT_CGHT_BGD  where  bgdh='" + bgdh + "' ; ";
                    sql += "delete from ht_bdwxx where htbh=(select HTBH from ht_cght_BGD where bgdh='" + bgdh + "'  ) ; ";
                    sql += "insert into HT_BDWXX ( HTBH, zclb, ggxh, dj, sl, zj, zt, spmc, yyssl, dyssl, yysje, dysje, pmmc, pmbm, zyjscs, jldw) select HTBH, zclb, ggxh, dj, sl, zj, zt, spmc, yyssl, dyssl, yysje, dysje, pmmc, pmbm, zyjscs, jldw from HT_BDWXX_bgd where bgdh='" + bgdh + "' ; ";
                    sql += "delete from ht_skzh where htbh=(select HTBH from ht_cght_BGD where bgdh='" + bgdh + "'  ) ; ";
                    sql += "insert into HT_SKZH(HTBH, gys, nsrsbh, khh, skzh, lxr, lxdh, zt) select HTBH, gys, nsrsbh, khh, skzh, lxr, lxdh, zt from HT_SKZH_bgd where bgdh = '" + bgdh + "' ; ";
                    sql += "delete from ht_fkjh where htbh=(select HTBH from ht_cght_BGD where bgdh='" + bgdh + "'  ) ; ";
                    sql += "insert into HT_FKJH( HTBH, jhnr, fkbl, fkje, fksj, fktj, zt) select HTBH, jhnr, fkbl, fkje, fksj, fktj, zt from HT_FKJH_bgd  where bgdh = '" + bgdh + "' ; ";
                    sql += "delete from ht_bzj where htbh=(select HTBH from ht_cght_BGD where bgdh='" + bgdh + "'  ) ; ";
                    sql += "insert into HT_bzj ( HTBH, bzjje, bzjdzsj, thje, thsj, sfth, zt, sjthsj, htlx, htmc) select HTBH, bzjje, bzjdzsj, thje, thsj, sfth, zt, sjthsj, htlx, htmc from ht_bzj_bgd  where bgdh='" + bgdh + "' ; ";
                    sql += "delete from ht_yfxx where htbh=(select HTBH from ht_cght_BGD where bgdh='" + bgdh + "'  ) ; ";
                    sql += "insert into HT_YFXX ( HTBH, yfmc, yffrdb, yfdbry, yflxdh, yffdzd, yfyb, yfshxydm, yfsfzhm, zt) select HTBH, yfmc, yffrdb, yfdbry, yflxdh, yffdzd, yfyb, yfshxydm, yfsfzhm, zt from ht_yfxx_bgd where bgdh='" + bgdh + "' ;";
                    sql += "update ht_cght set zfje=(select sum(zfje) from HT_Order where htbh=(select HTBH from ht_cght_BGD where bgdh='" + bgdh + "' )) " +
                        "where htbh=(select HTBH from ht_cght_BGD where bgdh='" + bgdh + "');";
                }
                if (htlx == "项目合同")
                {
                    sql = @"update HT_XMHT 
                       set HT_XMHT. sqr=b. sqr,
                       HT_XMHT. sqbm=b. sqbm,
                       HT_XMHT. sqrq=b. sqrq,
                       HT_XMHT. htmc=b. htmc,
                       HT_XMHT. htqdrq=b. htqdrq,
                       HT_XMHT. htje=b. htje,
                       HT_XMHT. htkssj=b. htkssj,
                       HT_XMHT. htjssj=b. htjssj,
                       HT_XMHT. jkfs=b. jkfs,
                       HT_XMHT. cfdd=b. cfdd,
                       HT_XMHT. htqddd=b. htqddd,
                       HT_XMHT. xmmc=b. xmmc,
                       HT_XMHT. bd=b. bd,
                       HT_XMHT. gspsje=b. gspsje,
                       HT_XMHT. kgrq=b. kgrq,
                       HT_XMHT. jgrq=b. jgrq,
                       HT_XMHT. yfk=b. yfk,
                       HT_XMHT. xmjl=b. xmjl,
                       HT_XMHT. xmhtlx=b. xmhtlx,
                       HT_XMHT. zrqxq=b. zrqxq,
                       HT_XMHT. fkzytj=b. fkzytj,
                       HT_XMHT. htgfzyyw=b. htgfzyyw,
                       HT_XMHT. wyzr=b. wyzr,
                       HT_XMHT. qtsx=b. qtsx,
                       HT_XMHT.zt='3',
                       HT_XMHT.zbcjdh=b.zbcjdh,
                       HT_XMHT.bmdm=b.bmdm
                       from HT_XMHT a
                       inner join HT_XMHT_BGD b
                       on a.htbh=(select HTBH from HT_XMHT_BGD where bgdh='" + bgdh + "' ) and b.htbh=(select HTBH from HT_XMHT_BGD where bgdh='" + bgdh + "' ) and b.bgdh='" + bgdh + "' ; ";
                    sql += "update ht_xmht_BGD set zt='3' where  bgdh='" + bgdh + "'  ; ";
                    sql += "update ht_skzh set zt='3' where htbh=(select HTBH from HT_XMHT_BGD where bgdh='" + bgdh + "' )  ; ";
                    sql += "update ht_fkjh set zt='3' where htbh=(select HTBH from HT_XMHT_BGD where bgdh='" + bgdh + "' ) ; ";
                    sql += "update ht_bzj set zt='3' where htbh=(select HTBH from HT_XMHT_BGD where bgdh='" + bgdh + "' ) ; ";
                    sql += "update ht_yfxx set zt='3' where htbh=(select HTBH from HT_XMHT_BGD where bgdh='" + bgdh + "' )  ; ";
                }
                if (htlx == "通用付款合同")
                {
                    sql += "update ht_tyfkht_bgd set zt='3'  where bgdh='" + bgdh + "' ; ";
                    sql += "delete ht_tyfkht where htbh=(select HTBH from ht_tyfkht_BGD where bgdh='" + bgdh + "' ) ; ";
                    sql += @"insert into HT_TYFKHT ( sqr, sqbm, sqrq, jfmc, jffrdb, jfdbry, jflxdh, jffdzd, jfyb, jfshxydm, jfsfzhm, yfmc, yffrdb, yfdbry, yflxdh, yffdzd, yfyb, yfshxydm, yfsfzhm, bfmc, bffrdb, bfdbry, bflxdh, bffdzd, 
                      bfyb, bfshxydm, bfsfzhm, htmc, htbh, htqdrq, htje, htkssj, htjssj, jkfs, cfdd, htqddd, fkzytj, htgfzyyw, wyzr, qtsx, zt, bmdm, zfje, bgdh, cgptbm)
                      select  sqr, sqbm, sqrq, jfmc, jffrdb, jfdbry, jflxdh, jffdzd, jfyb, jfshxydm, jfsfzhm, yfmc, yffrdb, yfdbry, yflxdh, yffdzd, yfyb, yfshxydm, yfsfzhm, bfmc, bffrdb, bfdbry, bflxdh, bffdzd, 
                      bfyb, bfshxydm, bfsfzhm, htmc, htbh, htqdrq, htje, htkssj, htjssj, jkfs, cfdd, htqddd, fkzytj, htgfzyyw, wyzr, qtsx, zt, bmdm, zfje, bgdh, cgptbm
                      from HT_TYFKHT_BGD  where bgdh='" + bgdh + "' ; ";
                    sql += "delete from ht_bdwxx where htbh=(select HTBH from ht_tyfkht_bgd where bgdh='" + bgdh + "'  ) ; ";
                    sql += "insert into HT_BDWXX ( HTBH, zclb, ggxh, dj, sl, zj, zt, spmc, yyssl, dyssl, yysje, dysje, pmmc, pmbm, zyjscs, jldw) select HTBH, zclb, ggxh, dj, sl, zj, zt, spmc, yyssl, dyssl, yysje, dysje, pmmc, pmbm, zyjscs, jldw from HT_BDWXX_bgd where bgdh='" + bgdh + "' ; ";
                    sql += "delete from ht_skzh where htbh=(select HTBH from ht_tyfkht_bgd where bgdh='" + bgdh + "'  ) ; ";
                    sql += "insert into HT_SKZH(HTBH, gys, nsrsbh, khh, skzh, lxr, lxdh, zt) select HTBH, gys, nsrsbh, khh, skzh, lxr, lxdh, zt from HT_SKZH_bgd where bgdh = '" + bgdh + "' ; ";
                    sql += "delete from ht_fkjh where htbh=(select HTBH from ht_tyfkht_bgd where bgdh='" + bgdh + "'  ) ; ";
                    sql += "insert into HT_FKJH( HTBH, jhnr, fkbl, fkje, fksj, fktj, zt) select HTBH, jhnr, fkbl, fkje, fksj, fktj, zt from HT_FKJH_bgd  where bgdh = '" + bgdh + "' ; ";
                    sql += "delete from ht_bzj where htbh=(select HTBH from ht_tyfkht_bgd where bgdh='" + bgdh + "'  ) ; ";
                    sql += "insert into HT_bzj ( HTBH, bzjje, bzjdzsj, thje, thsj, sfth, zt, sjthsj, htlx, htmc) select HTBH, bzjje, bzjdzsj, thje, thsj, sfth, zt, sjthsj, htlx, htmc from ht_bzj_bgd  where bgdh='" + bgdh + "' ; ";
                    sql += "delete from ht_yfxx where htbh=(select HTBH from ht_tyfkht_bgd where bgdh='" + bgdh + "'  ) ; ";
                    sql += "insert into HT_YFXX ( HTBH, yfmc, yffrdb, yfdbry, yflxdh, yffdzd, yfyb, yfshxydm, yfsfzhm, zt) select HTBH, yfmc, yffrdb, yfdbry, yflxdh, yffdzd, yfyb, yfshxydm, yfsfzhm, zt from ht_yfxx_bgd where bgdh='" + bgdh + "' ;";
                    sql += "update ht_tyfkht set zfje=(select sum(zfje) from HT_Order where htbh=(select HTBH from ht_tyfkht_bgd where bgdh='" + bgdh + "' )) " +
                       "where htbh=(select HTBH from ht_tyfkht_bgd where bgdh='" + bgdh + "');";
                }
                if (htlx == "租赁合同")
                {
                    sql = "update ht_zlht_BGD set zt='3' where  bgdh='" + bgdh + "'  ; ";

                    sql += "delete ht_zlht where htbh=(select HTBH from HT_ZLHT_BGD where bgdh='" + bgdh + "' )  ; ";
                    sql += @"insert into  HT_ZLHT (htbh, sqr, sqbm, sqrq, cqrmc, cqrhm, cqrfrdb, cqrdbry, cqrlxdh, cqrfdzd, cqryb, cqrshxydm, 
                             cqrsfzhm, czrzhbh,czrmc, czrfrdb, czrdbry, czrlxdh, czrfdzd, czryb, czrshxydm, czrsfzhm, dgfmc, dgffrdb, dgfdbry, dgflxdh, 
                             dgffdzd, dgfyb, dgfshxydm, dgfsfzhm, xmmc, htmc, htlx, sfxz, htqdrq, htqdksrq, htqdjsrq, htqx, htqddd, cfdd, htsm, 
                             zlyt, htjzmj, htsymj, gtmj, czmj, zxkssj, zxjssj, zxqx, qqqmq, zlkssj, zljssj, zlq, zjfs, fkzq, sfrq, sfje, ck, yzj, 
                             ysdf, zzj, wyxz, ywyf, skqx, sz, pt, qt, skgz, tqjcx, htqd, tqjy, tqjch, xzx, wyj, jfwyj, yfwyj, bhtyts, jfz, yfz,
                              bfz, zt, bmdm, zfje,bgdh,cqrkhh,cqryhzh,czrlx,czrhm,czrkhh,czryhzh,xmbh,zzjgdm,zzjgmc,cjrq,ptjybh,znjbl,jylx,yhtbh,sssq,bz,kplx,sssqbm,zybm,qtsm,skfsx,cqrdm)
                              select htbh, sqr, sqbm, sqrq, cqrmc, cqrhm, cqrfrdb, cqrdbry, cqrlxdh, cqrfdzd, cqryb, cqrshxydm, cqrsfzhm,czrzhbh, czrmc, czrfrdb, czrdbry,
                                czrlxdh, czrfdzd, czryb, czrshxydm, czrsfzhm, dgfmc, dgffrdb, dgfdbry, dgflxdh, dgffdzd, dgfyb, dgfshxydm, 
                              dgfsfzhm, xmmc, htmc, htlx, sfxz, htqdrq, htqdksrq, htqdjsrq, htqx, htqddd, cfdd, htsm, zlyt, htjzmj, htsymj, gtmj, czmj, 
                                zxkssj, zxjssj, zxqx, qqqmq, zlkssj, zljssj, zlq, zjfs, fkzq, sfrq, sfje, ck, yzj, ysdf, zzj, wyxz, ywyf, skqx, sz, pt, qt, 
                                skgz, tqjcx, htqd, tqjy, tqjch, xzx, wyj, jfwyj, yfwyj, bhtyts, jfz, yfz, bfz, zt, bmdm, zfje,
                              bgdh,cqrkhh,cqryhzh,czrlx,czrhm,czrkhh,czryhzh,xmbh,zzjgdm,zzjgmc,cjrq,ptjybh,znjbl,jylx,yhtbh,sssq,bz,kplx,sssqbm,zybm,qtsm,skfsx,cqrdm from ht_zlht_bgd where bgdh='" + bgdh + "' ; ";

                    sql += "delete ht_zcxx where htbh=(select HTBH from HT_ZLHT_BGD where bgdh='" + bgdh + "'  ) ; ";
                    sql += "insert into ht_zcxx (HTBH, zcbh, zcmc, zcbw, zclx, zcyt, jylx, ssdw, mjsl, cjj,jgdw,jydw ) select HTBH, zcbh, zcmc, zcbw, zclx, zcyt, jylx, ssdw, mjsl, cjj,jgdw,jydw from ht_zcxx_bgd  where bgdh='" + bgdh + "' ; ";


                    sql += "delete ht_bzj where htbh=(select HTBH from HT_ZLHT_BGD where bgdh='" + bgdh + "'  ) ; ";
                    sql += "insert into HT_bzj ( HTBH, bzjje, bzjdzsj, thje, thsj, sfth, zt, sjthsj, htlx, htmc) select HTBH, bzjje, bzjdzsj, thje, thsj, sfth, zt, sjthsj, htlx, htmc from ht_bzj_bgd  where bgdh='" + bgdh + "' ; ";

                    sql += "delete HT_ZLHT_BDZJ where htbh=(select HTBH from HT_ZLHT_BGD where bgdh='" + bgdh + "'  ) ; ";
                    sql += " insert into HT_ZLHT_BDZJ( HTBH, BDZJ, GLF) select   HTBH, BDZJ, GLF from HT_ZLHT_BDZJ_bgd where bgdh='" + bgdh + "' ; ";

                    sql += "delete HT_skjh where htbh=(select HTBH from HT_ZLHT_BGD where bgdh='" + bgdh + "'  ) ; ";
                    sql += " insert into HT_skjh(listid, HTBH, skfs, qs, jhskbl, jhskje, jhskrq, jhsknr,ssnd,skqj) select listid, HTBH, skfs, qs, jhskbl, jhskje, jhskrq, jhsknr,ssnd,skqj from HT_skjh_bgd where bgdh='" + bgdh + "' ; ";
                    sql += "update HT_ZLHT set zfje=(select sum(zfje) from HT_Order where htbh=(select HTBH from HT_ZLHT_BGD where bgdh='" + bgdh + "' )) " +
                       "where htbh=(select HTBH from HT_ZLHT_BGD where bgdh='" + bgdh + "');";
                    sql += "delete from ht_yys where  htbh in (select HTBH from HT_ZLHT_BGD where bgdh='" + bgdh + "'  ) ; ";
                    sql += "insert into ht_yys select htbh,nd,yf,yszj,ksyf,jsyf  from ht_yys_bgd where  htbh=(select HTBH from HT_ZLHT_BGD where bgdh='" + bgdh + "'  ) ; ";
                    sql += "delete from ht_srqrb where  htbh=(select HTBH from HT_ZLHT_BGD where bgdh='" + bgdh + "'  ) ; ";
                    sql += "insert into ht_srqrb select htbh,qc,ksrq,jsrq,yzj  from ht_srqrb_bgd where  htbh=(select HTBH from HT_ZLHT_BGD where bgdh='" + bgdh + "'  ) ; ";
                }
                if (htlx == "通用收款合同")
                {
                    sql += "update ht_tyskht_bgd set zt='3'  where bgdh='" + bgdh + "' ; ";
                    sql += "delete ht_tyskht where htbh=(select HTBH from ht_tyskht_bgd where bgdh='" + bgdh + "' ) ; ";
                    sql += @"insert into HT_TYSKHT (sqr, sqbm, sqrq, jfmc, jffrdb, jfdbry, jflxdh, jffdzd, jfyb, jfshxydm, jfsfzhm, yfmc, yffrdb, yfdbry, yflxdh, yffdzd, yfyb, yfshxydm, yfsfzhm, bfmc, bffrdb, bfdbry, bflxdh, bffdzd, 
                      bfyb, bfshxydm, bfsfzhm, htmc, htbh, htqdrq, htje, htkssj, htjssj, jkfs, cfdd, htqddd, fkzytj, htgfzyyw, wyzr, qtsx, zt, bmdm, zfje, bgdh, skgz) 
                      select sqr, sqbm, sqrq, jfmc, jffrdb, jfdbry, jflxdh, jffdzd, jfyb, jfshxydm, jfsfzhm, yfmc, yffrdb, yfdbry, yflxdh, yffdzd, yfyb, yfshxydm, yfsfzhm, bfmc, bffrdb, bfdbry, bflxdh, bffdzd, 
                      bfyb, bfshxydm, bfsfzhm, htmc, htbh, htqdrq, htje, htkssj, htjssj, jkfs, cfdd, htqddd, fkzytj, htgfzyyw, wyzr, qtsx, zt, bmdm, zfje, bgdh, skgz
                        from HT_TYSKHT_BGD where bgdh='" + bgdh + "' ;";
                    sql += "delete from ht_bdwxx where htbh=(select HTBH from HT_TYSKHT_BGD where bgdh='" + bgdh + "'  ) ; ";
                    sql += "insert into HT_BDWXX ( HTBH, zclb, ggxh, dj, sl, zj, zt, spmc, yyssl, dyssl, yysje, dysje, pmmc, pmbm, zyjscs, jldw) select HTBH, zclb, ggxh, dj, sl, zj, zt, spmc, yyssl, dyssl, yysje, dysje, pmmc, pmbm, zyjscs, jldw from HT_BDWXX_bgd where bgdh='" + bgdh + "' ; ";

                    sql += "delete HT_skjh where htbh=(select HTBH from HT_TYSKHT_BGD where bgdh='" + bgdh + "'  ) ; ";
                    sql += " insert into HT_skjh( HTBH, skfs, qs, jhskbl, jhskje, jhskrq, jhsknr) select  HTBH, skfs, qs, jhskbl, jhskje, jhskrq, jhsknr from HT_skjh_bgd where bgdh='" + bgdh + "' ; ";

                    sql += "delete ht_bzj where htbh=(select HTBH from HT_TYSKHT_BGD where bgdh='" + bgdh + "'  ) ; ";
                    sql += "insert into HT_bzj ( HTBH, bzjje, bzjdzsj, thje, thsj, sfth, zt, sjthsj, htlx, htmc) select HTBH, bzjje, bzjdzsj, thje, thsj, sfth, zt, sjthsj, htlx, htmc from ht_bzj_bgd  where bgdh='" + bgdh + "' ; ";

                    sql += "delete from ht_yfxx where htbh=(select HTBH from HT_TYSKHT_BGD where bgdh='" + bgdh + "'  ) ; ";
                    sql += "insert into HT_YFXX ( HTBH, yfmc, yffrdb, yfdbry, yflxdh, yffdzd, yfyb, yfshxydm, yfsfzhm, zt) select HTBH, yfmc, yffrdb, yfdbry, yflxdh, yffdzd, yfyb, yfshxydm, yfsfzhm, zt from ht_yfxx_bgd where bgdh='" + bgdh + "' ;";
                    sql += "update ht_tyskht set zfje=(select sum(zfje) from HT_Order where htbh=(select HTBH from ht_tyskht_bgd where bgdh='" + bgdh + "' )) " +
                       "where htbh=(select HTBH from ht_tyskht_bgd where bgdh='" + bgdh + "');";
                }
            }
            else if (zt == "4")
            {
                if (htlx == "采购合同")
                {

                    sql = "update HT_CGHT_BGD set zt='" + zt + "' where  bgdh='" + bgdh + "'  ; ";
                    sql += "update HT_CGHT set zt='3'where htbh=(select HTBH from HT_TYSKHT_BGD where bgdh='" + bgdh + "'  ) ; ";

                }
                if (htlx == "项目合同")
                {

                    sql = "update ht_xmht_BGD set zt='" + zt + "' where  bgdh='" + bgdh + "'  ; ";
                    sql += "update ht_xmht set zt='3'where htbh=(select HTBH from HT_TYSKHT_BGD where bgdh='" + bgdh + "'  ) ; ";
                }
                if (htlx == "通用付款合同")
                {
                    sql = "update ht_tyfkht_BGD set zt='" + zt + "' where  bgdh='" + bgdh + "'  ; ";
                    sql += "update ht_tyfkht set zt='3'where htbh=(select HTBH from HT_TYSKHT_BGD where bgdh='" + bgdh + "'  ) ; ";
                }
                if (htlx == "租赁合同")
                {

                    sql = "update ht_zlht_BGD set zt='" + zt + "' where bgdh='" + bgdh + "' ; ";

                    sql += "update ht_zlht set zt='3'where htbh=(select HTBH from HT_TYSKHT_BGD where bgdh='" + bgdh + "'  ) ; ";

                }
                if (htlx == "通用收款合同")
                {
                    sql += "update  ht_tyfkht_BGD set zt='" + zt + "' where  bgdh='" + bgdh + "'  ; ";
                    sql += "update ht_tyfkht set zt='3'where htbh=(select HTBH from HT_TYSKHT_BGD where bgdh='" + bgdh + "'  ) ; ";
                }
            }
            else
            {
                if (htlx == "采购合同")
                {

                    sql = "update HT_CGHT_BGD set zt='" + zt + "' where  bgdh='" + bgdh + "'  ; ";

                }
                if (htlx == "项目合同")
                {

                    sql = "update ht_xmht_BGD set zt='" + zt + "' where  bgdh='" + bgdh + "'  ; ";
                }
                if (htlx == "通用付款合同")
                {
                    sql = "update ht_tyfkht_BGD set zt='" + zt + "' where  bgdh='" + bgdh + "'  ; ";
                }
                if (htlx == "租赁合同")
                {

                    sql = "update ht_zlht_BGD set zt='" + zt + "' where bgdh='" + bgdh + "' ; ";



                }
                if (htlx == "通用收款合同")
                {
                    sql += "update  ht_tyfkht_BGD set zt='" + zt + "' where  bgdh='" + bgdh + "'  ; ";
                }
            }
            NLog.Logger log = LogManager.GetCurrentClassLogger();
            log.Info(sql);
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        #endregion

        #region "合同验收"

        //获取验收单
        public static async Task<(DataTable, int)> GetHT_Accept(HT_AcceptQuerry querry)
        {
            string str = "  1=1 ";
            if (!string.IsNullOrEmpty(querry.htbh) && querry.htbh != "string")
            {
                str += "and a.htbh='" + querry.htbh + "'";
            }

          
            if (!string.IsNullOrEmpty(querry.htlx) && querry.htlx != "string")
            {
                str += " and a.htlx='" + querry.htlx + "'";
            }
            //if (!string.IsNullOrEmpty(querry.listid) && querry.listid != "string")
            //{
            //    str += " and listid='" + querry.listid + "'";
            //}


            string sql = @"select  a.ListID, a.HTBH, a.htlx, ysmc, bm, ysr,convert(varchar(10), ysrq, 120) ysrq, bz, a.zt, ysje, yssl, sfjx, pdjb, pddf, yxzje, jxje,b.htje,yysje from ht_ysd a left join vw_ht_skhtgl b on
a.HTBH = b.htbh left join(select htbh, sum(ysje) as yysje from HT_YSD group by htbh) c on a.htbh = c.htbh where " + str;
           
            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);

        }

        public static async Task<(IEnumerable<dynamic>, int)> GetHT_YSD(HT_AcceptQuerry querry)
        {
            string str = "  1=1 ";
            if (!string.IsNullOrEmpty(querry.htbh) && querry.htbh != "string")
            {
                str += "and a.htbh='" + querry.htbh + "'";
            }


            if (!string.IsNullOrEmpty(querry.htlx) && querry.htlx != "string")
            {
                str += " and a.htlx='" + querry.htlx + "'";
            }
            if (!string.IsNullOrEmpty(querry.htmc) && querry.htmc != "string")
            {
                str += " and (b.htmc like '%" + querry.htmc + "%' or d.htmc like '%"+querry.htmc+"%')";
            }
            if (!string.IsNullOrEmpty(querry.bm) && querry.bm != "string")
            {
                str += " and bm='" + querry.bm + "'";
            }
            if (!string.IsNullOrEmpty(querry.ysmc) && querry.ysmc != "string")
            {
                str += " and ysmc like '%" + querry.ysmc + "%'";
            }
            if (querry.eysje>0 && querry.eysje>=querry.sysje)
            {
                str += " and (ysje>="+querry.sysje+" and ysje<="+querry.eysje+")";
            }
            if (!string.IsNullOrEmpty(querry.zt) && querry.zt != "string")
            {
                str += " and a.zt='" + querry.zt + "'";
            }


            string sql = @"select  a.listid, a.htbh,(case when b.htlx is null then d.htlx else b.htlx end) as htlx,
ysmc, bm, ysr,(case when CONVERT(char(8),ysrq,112)='19000101' then NULL else  CONVERT(char(10),ysrq,120) end) ysrq, 
bz, a.zt, ysje, yssl, sfjx, pdjb, pddf, yxzje, jxje,(case when b.htje is null then d.htje else b.htje end) as htje,c.yysje,
(case when b.htje is null then d.htje-isnull(c.yysje,0) else b.htje-isnull(c.yysje,0) end) as wysje,
(case when b.htmc is null then d.htmc else b.htmc end) as htmc from ht_ysd a left join vw_ht_skhtgl b on
a.HTBH = b.htbh left join vw_ht_fkhtgl d on a.HTBH=d.htbh left join(select htbh, sum(ysje) as yysje from HT_YSD where zt='3' group by htbh) c 
on a.htbh = c.htbh where " + str;

            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            return await new RepositoryFactory().BaseRepository().FindList(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);
        }

        public static async Task<DataTable> GetHT_AcceptJE(string htlx,string htbh)
        {
            string sql = "";
            if (htlx == "采购合同")
            {
                sql = ";";
            }
            if (htlx == "项目合同")
            {
                sql = "select 'XMHT'+CONVERT(varchar,GETDATE(),112)+convert(varchar,(select isnull(max(ListID),0)+1 from HT_XMHT)) as htbh;";
            }
            if (htlx == "通用付款合同")
            {
                sql = "select 'FKHT'+CONVERT(varchar,GETDATE(),112)+convert(varchar,(select isnull(max(ListID),0)+1 from HT_TYFKHT)) as htbh;";
            }
            if (htlx == "租赁合同")
            {
                sql = "select 'ZLHT'+CONVERT(varchar,GETDATE(),112)+convert(varchar,(select isnull(max(ListID),0)+1 from HT_ZLHT)) as htbh;";
            }

            if (htlx == "通用收款合同")
            {
                sql = "select 'SKHT'+CONVERT(varchar,GETDATE(),112)+convert(varchar,(select isnull(max(ListID),0)+1 from HT_TYSKHT)) as htbh;";
            }


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }



        //验收
        public static async Task<string> AcceptHT_YS(HT_Accept ht,bool isadd)
        {
   
            HT_AcceptHT acceptht = ht.acceptht;
            if (isadd)
            {
              
                string sql = "insert into HT_YSD(listid,HTBH, htlx, ysmc, bm, ysr, ysrq, bz, zt, ysje,yssl,bmdm) values('"+acceptht.listid + "','" + acceptht.htbh + "','" + acceptht.htlx + "','" + acceptht.ysmc + "','" + acceptht.bm + "','" + acceptht.ysr + "','" + acceptht.ysrq + "','" + acceptht.bz + "','" + acceptht.zt + "','" + acceptht.ysje + "','" + acceptht.yssl + "','"+acceptht.bmdm+"') ;";
                if (acceptht.htlx == "采购合同")
                {

                    sql += "update HT_CGHT set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "' ; ";
                    //sql += "update HT_BDWXX set zt='"+acceptht.zt+"' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update ht_skzh set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update ht_fkjh set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update ht_bzj set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update ht_yfxx set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                }
                if (acceptht.htlx == "项目合同")
                {

                    sql += "update ht_xmht set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ;";
                    sql += "update ht_skzh set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update ht_fkjh set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "' ; ";
                    sql += "update ht_bzj set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "' ; ";
                    sql += "update ht_yfxx set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                }
                if (acceptht.htlx == "通用付款合同")
                {

                    sql += "update  ht_tyfkht set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ;";
                    //sql += "update HT_BDWXX set zt='"+acceptht.zt+"' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update ht_skzh set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update ht_fkjh set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update ht_bzj set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update ht_yfxx set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                }
                if (acceptht.htlx == "租赁合同")
                {

                    sql += "update HT_ZLHT set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ;";
                    sql += "update HT_ZLHT_JBXX set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update HT_ZLHT_BDZJ set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";

                    sql += "update ht_bzj set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                }
                if (acceptht.htlx == "通用收款合同")
                {

                    sql += "update  ht_tyskht set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ;";
                    // sql += "update HT_BDWXX set zt='"+acceptht.zt+"' where htbh='" + acceptht.htbh + "'  ; ";

                    sql += "update ht_skjh set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update ht_bzj set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update ht_yfxx set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";

                }
                await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            }
            else
            {
                string sql = "update HT_YSD set HTBH='"+acceptht.htbh+"', htlx='"+acceptht.htlx+"', ysmc='"+acceptht.ysmc+"', bm='"+acceptht.bm+"', ysr='"+acceptht.bm+"', ysrq='"+acceptht.ysrq+"', bz='"+acceptht.bz+"', zt='"+acceptht.zt+"', ysje='"+acceptht.ysje+"',yssl='"+acceptht.yssl+"',bmdm='"+acceptht.bmdm+"'  where listid='"+acceptht.listid+"' ;";
                if (acceptht.htlx == "采购合同")
                {

                    sql += "update HT_CGHT set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "' ; ";
                    //sql += "update HT_BDWXX set zt='"+acceptht.zt+"' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update ht_skzh set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update ht_fkjh set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update ht_bzj set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update ht_yfxx set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                }
                if (acceptht.htlx == "项目合同")
                {

                    sql += "update ht_xmht set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ;";
                    sql += "update ht_skzh set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update ht_fkjh set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "' ; ";
                    sql += "update ht_bzj set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "' ; ";
                    sql += "update ht_yfxx set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                }
                if (acceptht.htlx == "通用付款合同")
                {

                    sql += "update  ht_tyfkht set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ;";
                    //sql += "update HT_BDWXX set zt='"+acceptht.zt+"' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update ht_skzh set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update ht_fkjh set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update ht_bzj set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update ht_yfxx set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                }
                if (acceptht.htlx == "租赁合同")
                {

                    sql += "update HT_ZLHT set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ;";
                    sql += "update HT_ZLHT_JBXX set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update HT_ZLHT_BDZJ set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";

                    sql += "update ht_bzj set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                }
                if (acceptht.htlx == "通用收款合同")
                {

                    sql += "update  ht_tyskht set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ;";
                    // sql += "update HT_BDWXX set zt='"+acceptht.zt+"' where htbh='" + acceptht.htbh + "'  ; ";

                    sql += "update ht_skjh set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update ht_bzj set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";
                    sql += "update ht_yfxx set zt='" + acceptht.zt + "' where htbh='" + acceptht.htbh + "'  ; ";

                }
                await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            }
            foreach (HT_AcceptBDWXX acceptbdwxx in ht.acceptbdwxx)
            {
                acceptbdwxx.ysid = ht.acceptht.listid;
                await AcceptHT_YSBDWXX(acceptbdwxx);
            }

            string sql1 = @"if ((select SUM(isnull(zj,0)) from HT_bdwxx where  htbh='" + acceptht.htbh + "')=(select SUM(isnull(yysje,0)) from HT_bdwxx where  htbh= '" + acceptht.htbh + "')) " +
      " begin " +
      "update HT_CGHT set zt=8 where htbh= '" + acceptht.htbh + "' " +
       "update ht_tyfkht set zt=8 where htbh= '" + acceptht.htbh + "' " +
        "update ht_zlht set zt=8 where htbh= '" + acceptht.htbh + "' " +
         "update ht_tyskht set zt=8 where htbh= '" + acceptht.htbh + "' " +
      "end  ";

            await new RepositoryFactory().BaseRepository().ExecuteSql(sql1);

            return acceptht.listid;

        }

        public static async Task SaveHT_YS(HT_Accept ht)
        {

            HT_AcceptHT acceptht = ht.acceptht;
            
                string sql = "delete from HT_YSD where listid="+ acceptht.listid+ " insert into HT_YSD(listid,HTBH, htlx, ysmc, bm, ysr, ysrq, bz, zt, ysje,yssl) values('"+acceptht.listid+"','" + acceptht.htbh + "','" + acceptht.htlx + "','" + acceptht.ysmc + "','" + acceptht.bm + "','" + acceptht.ysr + "','" + acceptht.ysrq + "','" + acceptht.bz + "','" + acceptht.zt + "','" + acceptht.ysje + "','" + acceptht.yssl + "') ;";

            
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);



        }

        public static async Task UpdateHT_YSStatus(string listid,string zt)
        {


            string sql = "Update HT_YSD set zt='" + zt + "' where listid='" + listid + "'";


            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);



        }

        public static async Task DeleteHT_YS(string listid)
        {


            string sql = "delete from HT_YSD where listid='" + listid + "'";


            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);



        }

        //验收标的物信息
        public static async Task<DataTable> AcceptHT_YSBDWXX(HT_AcceptBDWXX ht)
        {

            string sql = "update ht_bdwxx set yyssl =isnull(yyssl,0)+'" + ht.bcyssl + "'  where ListID ='" + ht.bid + "' ;";
               sql+= "update ht_bdwxx set dyssl =sl-yyssl, yysje =isnull(yysje,0)+'" + ht.bcysje+ "' where  HTBH='"+ht.htbh+"' and spmc='"+ht.spmc+"' and ggxh='"+ht.ggxh+"';";
            sql += "update ht_bdwxx set dysje =zj-yysje where  HTBH='" + ht.htbh + "' and spmc='" + ht.spmc + "' and ggxh='" + ht.ggxh + "';";
            sql += "update ht_bdwxx set zt ='" + ht.zt+ "' where  HTBH='" + ht.htbh +"' and spmc='" + ht.spmc +"' and ggxh='" + ht.ggxh + "';";
            if (string.IsNullOrEmpty(ht.listid))
            {
                ht.listid = DateTime.Now.ToString("yyyyMMddHHmmssfffffff");
            }
            sql += "delete from HT_BDWXX_YSD where ysid='"+ht.ysid+"'; Insert into HT_BDWXX_YSD values('" + ht.listid + "','"+ht.ysid+"','"+ht.htbh+ "','"+ht.zclb+"','"+ht.ggxh+"','"+ht.dj
                +"','"+ht.sl+"','"+ht.zj+"','','"+ht.spmc+"','"+ht.yyssl+"','"+ht.dyssl+"','"+ht.yysje+"','"+ht.dysje+"','','','','','"+ht.bcyssl+"','"+ht.bcysdj+"','"+ht.bcysje+"','"+ht.bid+"')";
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<IEnumerable<dynamic>> GetHT_YSDByListid(string listid)
        {
          
            string sql = @"SELECT ListID,bmdm,HTBH,htlx ,ysmc,bm,ysr,(case when CONVERT(char(8),ysrq,112)='19000101' then NULL else ysrq end) ysrq,bz,zt,ysje,yssl,sfjx,pdjb,pddf,yxzje,jxje from ht_Ysd  where listid='" + listid+"'";

         
            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }

        public static async Task<DataTable> GetHT_CGHTByListidx(string listid)
        {

            string sql = @"select a.*,b.yysje,a.htje-isnull(b.yysje,0) as wysje from HT_CGHT a left join (select htbh,sum(isnull(ysje,0)) as yysje 
from HT_YSD where listid<>'"+listid+"' group by htbh) b on a.htbh=b.HTBH where a.htbh=( select htbh from ht_Ysd  where listid='" + listid + "' )";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);
        }

        public static async Task<DataTable> GetHT_BDWXXByListidx(string listid)
        {

            string sql = @" select isnull(sum(zj),0) as zj from HT_BDWXX where htbh=( select htbh from ht_Ysd  where listid='" + listid + "')";


            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);
        }

        public static async Task<IEnumerable<dynamic>> GetHT_CGHTByListid(string listid)
        {

            string sql = @"select a.*,b.yysje,a.htje-isnull(b.yysje,0) as wysje from HT_CGHT a left join (select htbh,sum(isnull(ysje,0)) as yysje 
from HT_YSD where zt='3' group by htbh) b on a.htbh=b.HTBH where a.htbh=( select htbh from ht_Ysd  where listid='" + listid + "')";


            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }

        public static async Task<IEnumerable<dynamic>> GetHT_BDWXXByListid(string listid)
        {

            string sql = @" select * from HT_BDWXX where htbh=( select htbh from ht_Ysd  where listid='" + listid + "')";


            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }

        public static async Task<IEnumerable<dynamic>> GetHT_BDWXX_YSByListid(string listid)
        {

            string sql = @" select * from HT_BDWXX_YSD where ysid='" + listid+"'";


            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }


        #endregion


        #region"下拉框弹窗"

        public static async Task<DataTable> GetHT_JFXX(string jfmc)
        {

            string str = "  1=1 ";
            if (!string.IsNullOrEmpty(jfmc) && jfmc != "string")
            {
                str += "and jfmc like '%" + jfmc + "%'";
            }
            string sql = "select * from vw_ht_jfxx where "+str ;
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> GetHT_YFXX(string yfmc)
        {

            string str = "  1=1 ";
            if (!string.IsNullOrEmpty(yfmc) && yfmc != "string")
            {
                str += "and yfmc like '%" + yfmc + "%'";
            }
            string sql = "select * from vw_ht_yfxx where " + str;
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        public static async Task<DataTable> GetHT_BFXX(string bfmc)
        {

            string str = "  1=1 ";
            if (!string.IsNullOrEmpty(bfmc) && bfmc != "string")
            {
                str += "and bfmc like '%" + bfmc + "%'";
            }
            string sql = "select * from vw_ht_bfxx where " + str;
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }


        public static async Task<DataTable> GetHT_SKZHXX(string gys)
        {

            string str = "  1=1 ";
            if (!string.IsNullOrEmpty(gys) && gys != "string")
            {
                str += "and gys like '%" + gys + "%'";
            }
            string sql = "select * from vw_ht_skzh where " + str;
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        #endregion

        #region "出租方信息"
        public static async Task<DataTable> GetCZFXX(string czfmc,string listid,string deptid)
        {
            string sql = "select * from ht_czfxx where 1=1 and deptid='"+ deptid + "' ";
            if (!string.IsNullOrEmpty(czfmc))
            {
                sql += " and czfmc like '%"+czfmc+"%'";
            }
            if (!string.IsNullOrEmpty(listid))
            {
                sql += " and listid='"+listid+"'";
            }
            return await new RepositoryFactory().BaseRepository().FindTable(sql,null);
        }
        public static async Task InsertCZFXX(ht_czfxx xx)
        {
            await new RepositoryFactory().BaseRepository().Insert(xx);
        }

        public static async Task UpdateCZFXX(ht_czfxx xx)
        {
            await new RepositoryFactory().BaseRepository().Update(xx);
        }
        public static async Task DeleteCZFXX(string listid)
        {
            string sql = "delete from ht_czfxx where listid='"+listid+"'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }
        #endregion

        #region "公建房"
        public static async Task<(IEnumerable<dynamic>, int)> getht_gjf(ht_gjfCondition querry)
        {
            string str = "and   1=1 ";
            if (!string.IsNullOrEmpty(querry.zcmc) && querry.zcmc != "string")
            {
                str += "and zcmc like '%" + querry.zcmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.zcdm) && querry.zcdm != "string")
            {
                str += " and zcdm like '%" + querry.zcdm + "%'";
            }
            if (!string.IsNullOrEmpty(querry.zclbdm) && querry.zclbdm != "string")
            {
                str += " and zclbdm = '" + querry.zclbdm + "'";
            }
            if (!string.IsNullOrEmpty(querry.ssdwdm) && querry.ssdwdm != "string")
            {
                str += " and ssdwdm='" + querry.ssdwdm + "'";
            }
            if (!string.IsNullOrEmpty(querry.zt) && querry.zt != "string")
            {
                str += " and zt='" + querry.zt + "'";
            }
            if (!string.IsNullOrEmpty(querry.zcsxdm) && querry.zcsxdm != "string")
            {
                str += " and zcsxdm = '" + querry.zcsxdm + "'";
            }
            if (querry.sxzmj != null && querry.exzmj != null)
            {
                if (querry.exzmj > querry.sxzmj)
                {
                    
                    str += " and (xzmj>='" + querry.sxzmj + "' and xzmj<='" + querry.exzmj + "')";
                }
            }

            string sql = @"select * from vw_ht_gjf where (dwdm in " + querry.DepartID + ")" + str;
            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            //return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.PageSize, querry.Current);
            return await new RepositoryFactory().BaseRepository().FindList(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);
        }

        public static async Task insertht_gjf(ht_gjf gjf)
        {
            await new RepositoryFactory().BaseRepository().Insert(gjf);
        }

        public static async Task deleteht_gjf(string id)
        {
            string sql = "delete from ht_gjf where id='"+id+"'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }
        public static async Task updateht_gjf(ht_gjf gjf)
        {
            await deleteht_gjf(gjf.id);
            await new RepositoryFactory().BaseRepository().Insert(gjf);
        }

        public static async Task Updategjfstatus(string id, string zt)
        {
            string sql = "update ht_gjf set zt='"+zt+"' where id='"+id+"'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }

        public static async Task<DataTable> getht_gjfentity(string id)
        {
            string sql = "select * from ht_gjf where id='" + id + "'";
           return await new RepositoryFactory().BaseRepository().FindTable(sql,null);
        }
        #endregion

        #region "产交合同变更"
        public static async Task InsertContract_BGD(EnterContract enter)
        {
            int id = 0;
            if (enter.ht.listid == null)
            {
                 id = 0;
            }
            else
            {
                 id = Convert.ToInt32(enter.ht.listid);
            }
            await deleteContract_BGDbybgdh(enter.ht.bgdh);
            await insertContract_BGD(enter.ht);
            await deleteAssets_BGD(enter.ht.projcode,enter.ht.bgdh);
            if (enter.zcxx != null)
            {
                foreach (assets_BGD zc in enter.zcxx)
                {
                    zc.bgdh = enter.ht.bgdh;
                    await new RepositoryFactory().BaseRepository().Insert(zc);
                }
            }
            await deletecontractpaln_bgd(enter.ht.projcode, enter.ht.bgdh);
            if (enter.skjh != null)
            {
                foreach (ContractPlan_BGD skjh in enter.skjh)
                {
                    skjh.bgdh = enter.ht.bgdh;
                    skjh.projcode = enter.ht.projcode;
                    await new RepositoryFactory().BaseRepository().Insert(skjh);
                }
            }
            await DeleteHT_BZJ(enter.ht.projcode);
            foreach (HT_BZJ bzj in enter.bzj)
            {
                if (bzj.htbh != enter.ht.projcode)
                {
                    bzj.htbh = enter.ht.projcode;
                }
                await InsertHT_BZJ(bzj);
            }
           
            if (enter.srqrb != null)
            {
                await deleteht_srqkb_bgd(enter.ht.contractcode, enter.ht.bgdh);
                foreach (ht_srqrb_bgd sr in enter.srqrb)
                {
                    if (string.IsNullOrEmpty(sr.bgdh))
                    {
                        sr.bgdh = enter.ht.bgdh;
                    }
                    await insertht_srqkb_bgd(sr);
                }
            }
            if (enter.yys != null)
            {
                await deleteht_yys_bgd(enter.ht.contractcode, enter.ht.bgdh);
                foreach (ht_yys_bgd yys in enter.yys)
                {
                    if (string.IsNullOrEmpty(yys.bgdh))
                    {
                        yys.bgdh = enter.ht.bgdh;
                    }
                   
                    await insertht_yys_bgd(yys);
                }
            }
        }
        public static async Task deleteContract_BGDbybgdh(string id)
        {
            string sql = "delete from Contract_BGD where bgdh='" + id + "'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }
        public static async Task deleteContract_BGD(string id)
        {
            string sql = "delete from Contract_BGD where listid='" + id + "'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }
        public static async Task insertContract_BGD(Contract_BGD bgd)
        {
            if (bgd.firstrent == null)
            {
                bgd.firstrent = 0;
            }
            if (bgd.ywyf == null)
            {
                bgd.ywyf = 0;
            }
            if (bgd.yzj == null)
            {
                bgd.yzj = 0;
            }
            if (bgd.zlmj == null)
            {
                bgd.zlmj = 0;
            }
            if (bgd.ysdf == null)
            {
                bgd.ysdf = 0;
            }
            string sql = @"INSERT INTO Contract_BGD(projcode,areacode,contractfrom,contractcode,contractname,partya,partyb,contractstartdate,contractenddate ,contractcreatedate
           ,ttlamt,firstrent,acctname,acctnumb,accbankname,mobilephone,dutyperson,contractperson,contactmobile,auctionusertype,auctionusernumber,bank,bankaccount,auctiondate
           ,operatorname,operatorcardid,operatormobile,yhtbh,bz,ywyf,yzj,jylx,htsm ,zlmj,bgdh,bgsm ,skfs,tjr,tjrq,tjbmdm,zt,zxkssj,zxjssj,zxqx,zlkssj,zljssj,zlq,skgz,wyxz,ysdf,kplx,sssq,sssqbm,qtsm,skfsx)values('" + bgd.projcode + "','" + bgd.areacode + "'," +
               "'" + bgd.contractfrom + "','" + bgd.contractcode + "','" + bgd.contractname + "','" + bgd.partya + "','" + bgd.partyb + "','" + bgd.contractstartdate + "','" + bgd.contractenddate + "'," +
               "'" + bgd.contractcreatedate + "','" + bgd.ttlamt + "'," + bgd.firstrent + ",'" + bgd.acctname + "','" + bgd.acctnumb + "','" + bgd.accbankname + "','" + bgd.mobilephone + "'," +
               "'" + bgd.dutyperson + "','" + bgd.contractperson + "','" + bgd.contactmobile + "','" + bgd.auctionusertype + "','" + bgd.auctionusernumber + "','" + bgd.bank + "','" + bgd.bankaccount + "'," +
               "'" + bgd.auctiondate + "','" + bgd.operatorname + "','" + bgd.operatorcardid + "','" + bgd.operatormobile + "','" + bgd.yhtbh + "','" + bgd.bz + "'," + bgd.ywyf + "," + bgd.yzj + "," +
               "'" + bgd.jylx + "','" + bgd.htsm + "'," + bgd.zlmj + ",'" + bgd.bgdh + "','" + bgd.bgsm + "','" + bgd.skfs + "','" + bgd.tjr + "','" + bgd.tjrq + "','" + bgd.tjbmdm + "','" + bgd.zt + "'," +
               "'"+bgd.zxkssj+"','"+bgd.zxjssj+"','"+bgd.zxqx+"','"+bgd.zlkssj+"','"+bgd.zljssj+"','"+bgd.zlq+"','"+bgd.skgz+"','"+bgd.wyxz+"',"+bgd.ysdf+",'"+bgd.kplx+"','"+bgd.sssq+"','"+bgd.sssqbm+"','"+bgd.qtsm+"','"+bgd.skfsx + "')";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }

        public static async Task deleteAssets_BGD(string projcode, string bgdh)
        {
            string sql = "delete from assets_BGD where projcode='"+projcode+"' and bgdh='"+bgdh+"'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }

        public static async Task deletecontractpaln_bgd(string projcode, string bgdh)
        {
            string sql = "delete from ContractPlan_BGD where projcode='" + projcode + "' and bgdh='" + bgdh + "'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }

        public static async Task<DataTable> getcontract_bgd(string id)
        {
            string sql = "select * from Contract_BGD where bgdh='" + id+"'";
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);
        }

        public static async Task<IEnumerable<dynamic>> getcontract_bgdx(string id)
        {
            string sql = @"select *,projcode as xmbh from Contract_BGD  where bgdh='" + id + "'";
            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }
        public static async Task<IEnumerable<dynamic>> getcontractPlan_bgd(string bgdh)
        {
            string sql = @"select projcode,bz,a.skrq,je,sqbl,nd,fkfs,zqs,bgdh,a.skqj,c.skrq as sjskrq,skje as sjskje,a.ListID from vw_ContractPlan_BGD a
left join vw_maxskrq c on a.projcode=c.projectCode and a.ListID=c.planid left join
vw_sumskje d on a.projcode=d.projectCode and a.ListID=d.planid  where bgdh='" + bgdh+"'";
            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }
        public static async Task<IEnumerable<dynamic>> getAssets_bgd(string bgdh)
        {
            string sql = @"select * from assets_bgd a left join vw_Assets_BGD b on a.projcode=b.xmbh and a.bgdh=b.bgdh  where a.bgdh='" + bgdh + "'";
            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }

        public static async Task<IEnumerable<dynamic>> getBzj_bgd(string htbh)
        {
            string sql = @"select * from HT_BZJ  where htbh=(select projcode from Contract_BGD  where bgdh='" + htbh + "')";
            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }

        public static async Task<IEnumerable<dynamic>> getsrqrb_bgd(string htbh)
        {
            string sql = @"select * from ht_srqrb_bgd  where bgdh='" + htbh + "'";
            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }

        public static async Task<IEnumerable<dynamic>> getsrqrbx(string htbh,string bgdh)
        {
            if (string.IsNullOrEmpty(bgdh))
            {
                string sql = @"select * from ht_srqrb  where htbh='" + htbh + "'";
                return await new RepositoryFactory().BaseRepository().FindList(sql, null);
            }
            else
            {
                string sql = @"select * from ht_srqrb_bgd  where htbh='" + htbh + "' and bgdh='"+bgdh+"'";
                return await new RepositoryFactory().BaseRepository().FindList(sql, null);
            }
        }
        public static async Task<IEnumerable<dynamic>> getyys_bgd(string htbh)
        {
            string sql = @"select * from ht_yys_bgd  where bgdh='" + htbh + "'";
            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }
        public static async Task<IEnumerable<dynamic>> getyysx(string htbh,string bgdh)
        {
            if (string.IsNullOrEmpty(bgdh))
            {
                string sql = @"select * from ht_yys  where htbh='" + htbh + "'";
                return await new RepositoryFactory().BaseRepository().FindList(sql, null);
            }
            else
            {
                string sql = @"select * from ht_yys_bgd  where htbh='" + htbh + "' and bgdh='"+bgdh+"'";
                return await new RepositoryFactory().BaseRepository().FindList(sql, null);
            }
        }
        //public static async Task<IEnumerable<dynamic>> getyys_bgd(string htbh)
        //{
        //    string sql = @"select * from ht_yys  where htbh=(select projcode from Contract_BGD  where bgdh='" + htbh + "')";
        //    return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        //}

        public static async Task UpdateContractStatus(string id,string zt)
        {
            string sql = "update Contract_BGD set zt='"+zt+"' where bgdh='"+id+"';";
            if (zt == "3")
            {
                //sql += "delete from Contract where projcode=(select projcode from Contract_BGD where bgdh='" + id+"');";
                sql += "update  Contract set yhtbh=(select yhtbh from Contract_BGD where bgdh='" + id+"') where projcode=(select projcode from Contract_BGD where bgdh='" + id+"');";
                sql += "update  Contract set bz=(select bz from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                sql += "update  Contract set ywyf=(select ywyf from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                sql += "update  Contract set yzj=(select yzj from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                sql += "update  Contract set jylx=(select jylx from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                sql += "update  Contract set htsm=(select htsm from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                sql += "update  Contract set zlmj=(select zlmj from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                sql += "update  Contract set skfs=(select skfs from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                sql += "update  Contract set zxkssj=(select zxkssj from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                sql += "update  Contract set zxjssj=(select zxjssj from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";

                sql += "update  Contract set zxqx=(select zxqx from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                sql += "update  Contract set zlkssj=(select zlkssj from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                sql += "update  Contract set zljssj=(select zljssj from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                sql += "update  Contract set zlq=(select zlq from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                sql += "update  Contract set skgz=(select skgz from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                sql += "update  Contract set wyxz=(select wyxz from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                sql += "update  Contract set ysdf=(select ysdf from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                sql += "update  Contract set kplx=(select kplx from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                sql += "update  Contract set sssq=(select sssq from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                sql += "update  Contract set sssqbm=(select sssqbm from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                sql += "update  Contract set qtsm=(select qtsm from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                sql += "update  Contract set skfsx=(select skfsx from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                sql += "update  Contract set zlyt=(select zlyt from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                sql += "update  Contract set zzj=(select zzj from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                sql += "update  Contract set skfsx=(select skfsx from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                //     sql += @"INSERT INTO Contract(projcode,areacode,contractfrom,contractcode,contractname,partya,partyb,contractstartdate,contractenddate ,contractcreatedate
                //,ttlamt,firstrent,acctname,acctnumb,accbankname,mobilephone,dutyperson,contractperson,contactmobile,auctionusertype,auctionusernumber,bank,bankaccount,auctiondate
                //,operatorname,operatorcardid,operatormobile,yhtbh,bz,ywyf,yzj,jylx,htsm ,zlmj,skfs) select projcode,areacode,contractfrom,contractcode,contractname,partya,partyb,contractstartdate,contractenddate ,contractcreatedate
                //,ttlamt,firstrent,acctname,acctnumb,accbankname,mobilephone,dutyperson,contractperson,contactmobile,auctionusertype,auctionusernumber,bank,bankaccount,auctiondate
                //,operatorname,operatorcardid,operatormobile,yhtbh,bz,ywyf,yzj,jylx,htsm ,zlmj,skfs from Contract_BGD where bgdh='" + id+"';";
                sql += "delete from assets where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";
                sql += "insert into assets(projcode,assetcode,assetclass,assettransprice,priceunit,tradearea,tradeunit,assetid,zcbw,zdj)" +
                    " select projcode,assetcode,assetclass,assettransprice,priceunit,tradearea,tradeunit,assetid,zcbw,zdj from assets_BGD where bgdh='" + id + "'";
                //sql += "update assets set zcbw=(select zcbw from Contract_BGD where bgdh='" + id + "') where projcode=(select projcode from Contract_BGD where bgdh='" + id + "');";

                sql += "delete from ContractPlan where projcode=(select projcode from Contract_BGD where bgdh='" + id + "')";
                    sql += "INSERT INTO ContractPlan(projcode,bz,skrq,je,sqbl,nd,fkfs,zqs,skqj) select projcode,bz,skrq,je,sqbl,nd,fkfs,zqs,skqj from ContractPlan_BGD where bgdh='" + id + "'";
                sql += "delete HT_skjh where htbh in (select projcode from ContractPlan_BGD where bgdh='" + id + "'  ) ; ";
                sql += "declare @id int;set @id=isnull((select max(listid) from ht_skjh),0)+1; insert into HT_skjh(listid, HTBH, skfs, qs, jhskbl, jhskje, jhskrq, jhsknr) select @id+ROW_NUMBER() over (order by skrq), projcode, fkfs, zqs, sqbl, je, skrq, '' from ContractPlan_BGD where bgdh='" + id + "' ; ";
                sql += "delete from ht_yys where  htbh=(select HTBH from Contract_BGD where bgdh='" + id + "'  ) ; ";
                sql += "insert into ht_yys select htbh,nd,yf,yszj,ksyf,jsyf  from ht_yys_bgd where  htbh=(select HTBH from Contract_BGD where bgdh='" + id + "'  ) ; ";
                sql += "delete from ht_srqrb where  htbh=(select HTBH from Contract_BGD where bgdh='" + id + "'  ) ; ";
                sql += "insert into ht_srqrb select htbh,qc,ksrq,jsrq,yzj  from ht_srqrb_bgd where  htbh=(select HTBH from Contract_BGD where bgdh='" + id + "'  ) ; ";
            }
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }

        public static async Task<DataTable> getcontract(string htbh)
        {
            string sql = "select * from Contract where contractcode='" + htbh + "'";
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);
        }

        public static async Task<IEnumerable<dynamic>> getcontract_bgdx(int id)
        {
            string sql = @"select * from Contract_BGD  where listid=" + id;
            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }
        public static async Task<IEnumerable<dynamic>> getcontractPlan(string htbh)
        {
            string sql = @"select * from ht_skjh  where htbh=(select projcode from Contract where contractcode='" + htbh + "')";
            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }
        public static async Task<IEnumerable<dynamic>> getAssets(string htbh)
        {
            string sql = @"select * from assets a left join vw_ht_AssetsZC b on a.projcode=b.xmbh  where a.projcode=(select projcode from Contract where contractcode='" + htbh + "')";
            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }

        public static async Task<IEnumerable<dynamic>> getBzj(string htbh)
        {
            string sql = @"select * from HT_BZJ  where htbh=(select projcode from Contract where contractcode='" + htbh + "')";
            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }

        public static async Task<IEnumerable<dynamic>> getsrqrb(string htbh)
        {
            string sql = @"select * from ht_srqrb  where htbh=(select projcode from Contract where contractcode='" + htbh + "')";
            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }
        public static async Task<IEnumerable<dynamic>> getyys(string htbh)
        {
            string sql = @"select * from ht_yys  where htbh=(select projcode from Contract where contractcode='" + htbh + "')";
            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }
        #endregion

        #region "合同报表"
        public static async Task<(DataTable, int)> getcontractassets(assetquerry querry)
        {
            string sql = "select * from vw_contractasset where 1=1";
            if (!string.IsNullOrEmpty(querry.ssdw))
            {
                sql += " and ssdw like '%"+querry.ssdw+"%'";
            }
            if (!string.IsNullOrEmpty(querry.zcsx))
            {
                sql += " and zcsx ='"+querry.zcsx+"'";
            }
            if (!string.IsNullOrEmpty(querry.sssq))
            {
                sql += " and sssq like '%"+querry.sssq+"%'";
            }
            if (!string.IsNullOrEmpty(querry.cqr))
            {
                sql += " and cqr like '%"+querry.cqr+"%'";
            }
            if (querry.shtksrq != null && querry.ehtksrq != null)
            {
                if (Convert.ToDateTime(querry.shtksrq) <= Convert.ToDateTime(querry.ehtksrq))
                {
                    sql += " and (convert(datetime,htkssj)>='" + querry.shtksrq + "' and convert(datetime,htkssj)<='" + querry.ehtksrq + "')";
                }
            }
            if (querry.shtjsrq != null && querry.ehtjsrq != null)
            {
                if (Convert.ToDateTime(querry.shtjsrq) <= Convert.ToDateTime(querry.ehtjsrq))
                {
                    sql += " and (convert(datetime,htjssj)>='" + querry.shtjsrq + "' and convert(datetime,htjssj)<='" + querry.ehtjsrq + "')";
                }
            }
            if (Convert.ToDecimal(querry.ssnjq1) < Convert.ToDecimal(querry.esnjq1))
            {
                sql += " and (snjq1>="+ Convert.ToDecimal(querry.ssnjq1) + " and snjq1<="+ Convert.ToDecimal(querry.esnjq1) + ")";
            }
            if (Convert.ToDecimal(querry.ssnjq2) < Convert.ToDecimal(querry.esnjq2))
            {
                sql += " and (snjq2>=" + Convert.ToDecimal(querry.ssnjq2) + " and snjq2<=" + Convert.ToDecimal(querry.esnjq2) + ")";
            }
            if (Convert.ToDecimal(querry.sjzjq1) < Convert.ToDecimal(querry.ejzjq1))
            {
                sql += " and (jzjq1>=" + Convert.ToDecimal(querry.sjzjq1) + " and jzjq1<=" + Convert.ToDecimal(querry.ejzjq1) + ")";
            }
            if (Convert.ToDecimal(querry.sjzjq2) < Convert.ToDecimal(querry.ejzjq2))
            {
                sql += " and (jzjq2>=" + Convert.ToDecimal(querry.sjzjq2) + " and jzjq2<=" + Convert.ToDecimal(querry.ejzjq2) + ")";
            }
            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
          
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);
        }

        public static async Task<DataTable> getcontractassetsx(assetquerry querry)
        {
            string sql = "select * from vw_contractassetx where 1=1";
            if (!string.IsNullOrEmpty(querry.ssdw))
            {
                sql += " and ssdw like '%" + querry.ssdw + "%'";
            }
            if (!string.IsNullOrEmpty(querry.zcsx))
            {
                sql += " and zcsx ='" + querry.zcsx + "'";
            }
            if (!string.IsNullOrEmpty(querry.sssq))
            {
                sql += " and sssq like '%" + querry.sssq + "%'";
            }
            if (!string.IsNullOrEmpty(querry.cqr))
            {
                sql += " and cqr like '%" + querry.cqr + "%'";
            }
            if (querry.shtksrq != null && querry.ehtksrq != null)
            {
                if (Convert.ToDateTime(querry.shtksrq) <= Convert.ToDateTime(querry.ehtksrq))
                {
                    sql += " and (convert(datetime,htkssj)>='" + querry.shtksrq + "' and convert(datetime,htkssj)<='" + querry.ehtksrq + "')";
                }
            }
            if (querry.shtjsrq != null && querry.ehtjsrq != null)
            {
                if (Convert.ToDateTime(querry.shtjsrq) <= Convert.ToDateTime(querry.ehtjsrq))
                {
                    sql += " and (convert(datetime,htjssj)>='" + querry.shtjsrq + "' and convert(datetime,htjssj)<='" + querry.ehtjsrq + "')";
                }
            }
            if (Convert.ToDecimal(querry.ssnjq1) < Convert.ToDecimal(querry.esnjq1))
            {
                sql += " and (snjq1>=" + Convert.ToDecimal(querry.ssnjq1) + " and snjq1<=" + Convert.ToDecimal(querry.esnjq1) + ")";
            }
            if (Convert.ToDecimal(querry.ssnjq2) < Convert.ToDecimal(querry.esnjq2))
            {
                sql += " and (snjq2>=" + Convert.ToDecimal(querry.ssnjq2) + " and snjq2<=" + Convert.ToDecimal(querry.esnjq2) + ")";
            }
            if (Convert.ToDecimal(querry.sjzjq1) < Convert.ToDecimal(querry.ejzjq1))
            {
                sql += " and (jzjq1>=" + Convert.ToDecimal(querry.sjzjq1) + " and jzjq1<=" + Convert.ToDecimal(querry.ejzjq1) + ")";
            }
            if (Convert.ToDecimal(querry.sjzjq2) < Convert.ToDecimal(querry.ejzjq2))
            {
                sql += " and (jzjq2>=" + Convert.ToDecimal(querry.sjzjq2) + " and jzjq2<=" + Convert.ToDecimal(querry.ejzjq2) + ")";
            }
            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            //int start = (querry.Current - 1) * querry.Size;
            //int end = (querry.Current) * querry.Size;
            //sql += " and  rowNum > " + start + " And rowNum <= " + end;
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);
        }


        public static async Task<(IEnumerable<dynamic>, int)> GetQJ(reportQj querry)
        {
            string str = "and   1=1 ";
            if (!string.IsNullOrEmpty(querry.contractcode) && querry.contractcode != "string")
            {
                str += "and contractcode like'%" + querry.contractcode + "%'";
            }
            if (!string.IsNullOrEmpty(querry.partya) && querry.partya != "string")
            {
                str += "and partya='" + querry.partya + "'";
            }
            if (!string.IsNullOrEmpty(querry.assetcode) && querry.assetcode != "string")
            {
                str += "and assetcode='" + querry.assetcode + "'";
            }
            if (!string.IsNullOrEmpty(querry.contractname) && querry.contractname != "string")
            {
                str += " and contractname like '%" + querry.contractname + "%'";
            }
            if (!string.IsNullOrEmpty(querry.gdmc) && querry.gdmc != "string")
            {
                str += " and gdmc='" + querry.gdmc + "'";
            }
           
            if (Convert.ToDecimal(querry.sqjje)<=Convert.ToDecimal(querry.eqjje) & Convert.ToDecimal(querry.eqjje)>0)
            {
                
                    str += " and (qzje>='" + querry.sqjje + "' and qzje<='" + querry.eqjje + "')";
                
            }
            if (Convert.ToDecimal(querry.sday) <= Convert.ToDecimal(querry.eday) & Convert.ToDecimal(querry.eday) > 0)
            {

                str += " and (days>='" + querry.sday + "' and days<='" + querry.eday + "')";

            }

            string sql = @"select * from vw_reportQj where bmdm in " + querry.DepartID + str;
            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            // return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.PageSize, querry.Current);
            return await new RepositoryFactory().BaseRepository().FindList(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);

        }
        #endregion

        #region "合同终止"
        public static async Task<(IEnumerable<dynamic>, int)> getht_htzzList(ht_zzhtQuerry querry)
        {
            string str = "and   1=1 ";
            if (!string.IsNullOrEmpty(querry.htbh) && querry.htbh != "string")
            {
                str += "and htbh like '%" + querry.htbh + "%'";
            }
            if (!string.IsNullOrEmpty(querry.htmc) && querry.htmc != "string")
            {
                str += " and htmc like '%" + querry.htmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.htlx) && querry.htlx != "string")
            {
                str += " and htlx = '" + querry.htlx + "'";
            }
            if (!string.IsNullOrEmpty(querry.ssdwdm) && querry.ssdwdm != "string")
            {
                str += " and ssdwdm='" + querry.ssdwdm + "'";
            }
            if (!string.IsNullOrEmpty(querry.ssdwmc) && querry.ssdwmc != "string")
            {
                str += " and ssdwmc='" + querry.ssdwmc + "'";
            }
            if (!string.IsNullOrEmpty(querry.zt) && querry.zt != "string")
            {
                str += " and zt='" + querry.zt + "'";
            }
            if (!string.IsNullOrEmpty(querry.yf) && querry.yf != "string")
            {
                str += " and yf like '%" + querry.yf + "%'";
            }
            if (!string.IsNullOrEmpty(querry.djbm) && querry.djbm != "string")
            {
                str += " and id like '%"+querry.djbm+"%'";
            }
            if (querry.syje1 != null && querry.syje2 != null)
            {
                if (querry.syje1 >= querry.syje2)
                {

                    str += " and (syje>='" + querry.syje1 + "' and syje<='" + querry.syje2 + "')";
                }
            }

            string sql = @"select * from vw_ht_zzht where (bmdm in " + querry.DepartID + ")" + str;
            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            //return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.PageSize, querry.Current);
            return await new RepositoryFactory().BaseRepository().FindList(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);
        }

        public static async Task<(IEnumerable<dynamic>, int)> getht_htList(ht_zzhtQuerry querry)
        {
            string str = "and   1=1 ";
            if (!string.IsNullOrEmpty(querry.htbh) && querry.htbh != "string")
            {
                str += "and htbh like '%" + querry.htbh + "%'";
            }
            if (!string.IsNullOrEmpty(querry.htmc) && querry.htmc != "string")
            {
                str += " and htmc like '%" + querry.htmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.htlx) && querry.htlx != "string")
            {
                str += " and htlx = '" + querry.htlx + "'";
            }
            if (!string.IsNullOrEmpty(querry.ssdwdm) && querry.ssdwdm != "string")
            {
                str += " and ssdwdm='" + querry.ssdwdm + "'";
            }
            if (!string.IsNullOrEmpty(querry.zt) && querry.zt != "string")
            {
                str += " and zt='" + querry.zt + "'";
            }
            if (!string.IsNullOrEmpty(querry.yf) && querry.yf != "string")
            {
                str += " and yf like '" + querry.zt + "%'";
            }
            if (!string.IsNullOrEmpty(querry.htzt) && querry.htzt != "string")
            {
                str += " and htzt like '" + querry.htzt + "%'";
            }

            if (querry.syje1 != null && querry.syje2 != null)
            {
                if (querry.syje1 >= querry.syje2)
                {

                    str += " and (syje>='" + querry.syje1 + "' and syje<='" + querry.syje2 + "')";
                }
            }

            string sql = @"select * from vw_htlist where (bmdm in " + querry.DepartID + ")" + str;
            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            //return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.PageSize, querry.Current);
            return await new RepositoryFactory().BaseRepository().FindList(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);
        }

        public static async Task Insertht_zzht(ht_zzht ht)
        {
           await  new RepositoryFactory().BaseRepository().Insert(ht);
        }
        public static async Task deleteht_zzht(string id)
        {
            string sql = "delete from ht_zzht where id='"+id+"'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }

        public static async Task<IEnumerable<dynamic>> getht_zzht(string id)
        {
            string sql = "select * from vw_ht_zzht where id='"+id+"'";
            return await new RepositoryFactory().BaseRepository().FindList(sql,null);
        }

        public static async Task<IEnumerable<dynamic>> getht_zzhtx(string htbh)
        {
            string sql = "select * from vw_ht_zzht where htbh='" + htbh + "' and zt='3'";
            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }
        public static async Task<IEnumerable<dynamic>> getht_htBYhtbh(string id)
        {
            string sql = "select * from vw_htlist where htbh=(select htbh from vw_ht_zzht where id='"+id+"')";
            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }

        public static async Task Updateghtzzstatus(string id, string zt)
        {
            string sql = "update ht_zzht set zt='" + zt + "' where id='" + id + "'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }
        #endregion


        #region "收款计划"
        public static async Task<DataTable> getContractPlan(string htbh,string listid)
        {
            if (string.IsNullOrEmpty(listid))
            {
                string sql = @"select a.*,isnull(kpje, 0) as kpje,jhskje - isnull(kpje, 0) as wkpje,skje,(select max(collectionTime) from vw_ht_skxx d where a.htbh=d.projectCode and a.listid=d.planid) as skrq from ht_skjh a 
left join (select distinct projectCode,planid,isnull(sum(payAmount), 0) as kpje from vw_ht_skxx where collectiontype='已开票' group by projectCode,planid) b 
on a.HTBH = b.projectCode and a.ListID = b.planid
left join (select distinct projectCode,planid,isnull(sum(CollectionAmount), 0) as skje from vw_ht_skxx where collectiontype='已对账' group by projectCode,planid) c 
on a.HTBH = c.projectCode and a.ListID = c.planid
                            where a.jhskje > isnull(kpje, 0) and (a.htbh='" + htbh + "' or a.htbh=(select top 1 xmbh from vw_ht_skhtgl where htbh='"+htbh+"')) order by a.jhskrq";
                return await new RepositoryFactory().BaseRepository().FindTable(sql, null);
            }
            else
            {
                string sql = @"select a.*,isnull(kpje, 0) as kpje,jhskje - isnull(kpje, 0) as wkpje,skje,(select max(collectionTime) from vw_ht_skxx d where a.htbh=d.projectCode and a.listid=d.planid) from ht_skjh a 
left join (select distinct projectCode,planid,isnull(sum(payAmount), 0) as kpje from vw_ht_skxx where collectiontype='已开票' group by projectCode,planid) b 
on a.HTBH = b.projectCode and a.ListID = b.planid
left join (select distinct projectCode,planid,isnull(sum(CollectionAmount), 0) as skje from vw_ht_skxx where collectiontype='已对账' group by projectCode,planid) c 
on a.HTBH = c.projectCode and a.ListID = c.planid
                            where a.listid='" + listid + "'";
                return await new RepositoryFactory().BaseRepository().FindTable(sql, null);
            }
        }

        public static async Task<DataTable> getinvoice(string htbh)
        {
            string sql = @"select a.*,(case when a.payAmount=0 then '未开票' else '已开票' end) as kpzt,
(case when isnull(b.projectCode,'')='' then '未对账' else '已对账' end) as dzzt from ht_skxx a left join 
(select distinct projectCode,planid,invoiceID,serialNumber from ht_skxx where collectiontype='已对账') b 
on a.projectCode=b.projectCode and a.planid=b.planid and a.invoiceID=a.invoiceID and a.serialNumber=b.serialNumber 
 where a.collectiontype='已开票' and a.projectCode='" + htbh+"'";
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);
        }
        #endregion

        #region "欠缴情况"
        public static async Task<(IEnumerable<dynamic>, int)> getht_qjList(ht_qjQuerry querry)
        {
            string str = "and   1=1 ";
            if (!string.IsNullOrEmpty(querry.htbh) && querry.htbh != "string")
            {
                str += "and htbh like '%" + querry.htbh + "%'";
            }
            if (!string.IsNullOrEmpty(querry.htmc) && querry.htmc != "string")
            {
                str += " and htmc like '%" + querry.htmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.htlx) && querry.htlx != "string")
            {
                str += " and htlx = '" + querry.htlx + "'";
            }
            if (!string.IsNullOrEmpty(querry.jfmc) && querry.jfmc != "string")
            {
                str += " and jfmc like  '%" + querry.jfmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.zt) && querry.zt != "string")
            {
                str += " and zt = '" + querry.zt + "'";
            }
            if (!string.IsNullOrEmpty(querry.zjlc) && querry.zjlc != "string")
            {
                str += " and zjlc = '" + querry.zjlc + "'";
            }
            if (!string.IsNullOrEmpty(querry.yfmc) && querry.yfmc != "string")
            {
                str += " and yfmc  like  '%" + querry.yfmc + "%'";
            }
            string sql = @"select * from vw_qj where (bmdm in " + querry.DepartID + ")" + str;
            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            //return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.PageSize, querry.Current);
            return await new RepositoryFactory().BaseRepository().FindList(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);
        }

        public static async Task insertht_qj(ht_qj qj)
        { 
        await new RepositoryFactory().BaseRepository().Insert(qj);
        }

        public static async Task deleteht_qj(string listid)
        {
            string sql = "delete from ht_qj where listid='"+listid+"'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }

        public static async Task updateht_qj(string zt, string listid)
        {
            string sql = "update ht_qj set zt='"+zt+"' where listid='"+listid+"'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }

        public static async Task<IEnumerable<dynamic>> getht_skht(string id)
        {
            string sql = "select * from vw_ht_skhtgl where htbh=(select distinct htbh from ht_qj where listid='" + id + "')";
            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }

        public static async Task<IEnumerable<dynamic>> getht_skjh(string id)
        {
            DataTable table= await new RepositoryFactory().BaseRepository().FindTable("select jhid from ht_qj where listid='" + id + "'", null);
            string jhid = "";
            if (table.Rows.Count > 0)
            {
                jhid = table.Rows[0]["jhid"].ToString();
            }
            if (jhid == "")
            {
                return null;
            }

            string sql = "select a.*,isnull(kpje, 0) as kpje,jhskje - isnull(kpje, 0) as wkpje,skje," +
                "(select max(collectionTime) from vw_ht_skxx d where a.htbh=d.projectCode and a.listid=d.planid) from ht_skjh a left join " +
                "(select distinct projectCode,planid,isnull(sum(payAmount), 0) as kpje from vw_ht_skxx where collectiontype='已开票' group by projectCode,planid) b " +
                "on a.HTBH = b.projectCode and a.ListID = b.planid left join (select distinct projectCode,planid,isnull(sum(CollectionAmount), 0) as skje from vw_ht_skxx where collectiontype='已对账' group by projectCode,planid)" +
                " c on a.HTBH = c.projectCode and a.ListID = c.planid where listid in (" + jhid+")";
            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }

        public static async Task<IEnumerable<dynamic>> getht_qj(string id)
        {
            string sql = "select * from ht_qj where listid='" + id + "'";
            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }

        public static async Task<DataTable> getContractPlanlist(string htbh, string listid)
        {
            if (string.IsNullOrEmpty(listid))
            {
                string sql = @"select a.*,isnull(kpje, 0) as kpje,jhskje - isnull(kpje, 0) as wkpje,skje,(select max(collectionTime) from vw_ht_skxx d where a.htbh=d.projectCode and a.listid=d.planid) as skrq from ht_skjh a 
left join (select distinct projectCode,planid,isnull(sum(payAmount), 0) as kpje from vw_ht_skxx where collectiontype='已开票' group by projectCode,planid) b 
on a.HTBH = b.projectCode and a.ListID = b.planid
left join (select distinct projectCode,planid,isnull(sum(CollectionAmount), 0) as skje from vw_ht_skxx where collectiontype='已对账' group by projectCode,planid) c 
on a.HTBH = c.projectCode and a.ListID = c.planid
                            where a.jhskje > isnull(skje, 0) and jhskrq<getdate() and (a.htbh='" + htbh + "' or a.htbh=(select top 1 xmbh from vw_ht_skhtgl where htbh='"+htbh+"'))";
                return await new RepositoryFactory().BaseRepository().FindTable(sql, null);
            }
            else
            {
                string sql = @"select a.*,isnull(kpje, 0) as kpje,jhskje - isnull(kpje, 0) as wkpje,skje,(select max(collectionTime) from vw_ht_skxx d where a.htbh=d.projectCode and a.listid=d.planid) from ht_skjh a 
left join (select distinct projectCode,planid,isnull(sum(payAmount), 0) as kpje from vw_ht_skxx where collectiontype='已开票' group by projectCode,planid) b 
on a.HTBH = b.projectCode and a.ListID = b.planid
left join (select distinct projectCode,planid,isnull(sum(CollectionAmount), 0) as skje from vw_ht_skxx where collectiontype='已对账' group by projectCode,planid) c 
on a.HTBH = c.projectCode and a.ListID = c.planid
                            where a.listid='" + listid + "'";
                return await new RepositoryFactory().BaseRepository().FindTable(sql, null);
            }
        }
        #endregion

        #region "合同收款"
        public static async Task<(IEnumerable<dynamic>, int)> getht_skList(skQuerry querry)
        {
            string str = "and   1=1 ";
            if (!string.IsNullOrEmpty(querry.htbh) && querry.htbh != "string")
            {
                str += "and htbh like '%" + querry.htbh + "%'";
            }
            if (!string.IsNullOrEmpty(querry.htmc) && querry.htmc != "string")
            {
                str += " and htmc like '%" + querry.htmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.htlx) && querry.htlx != "string")
            {
                str += " and htlx = '" + querry.htlx + "'";
            }
            if (!string.IsNullOrEmpty(querry.jfmc) && querry.jfmc != "string")
            {
                str += " and jfmc  like  '%" + querry.jfmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.zt) && querry.zt != "string")
            {
                str += " and zt = '" + querry.zt + "'";
            }
            if (!string.IsNullOrEmpty(querry.skmc) && querry.skmc != "string")
            {
                str += " and skmc like '%" + querry.skmc + "%'";
            }
            if (Convert.ToDecimal(querry.eskje) >= Convert.ToDecimal(querry.sskje) & Convert.ToDecimal(querry.eskje)>0)
            {
                str += " and (CollectionAmount>="+querry.sskje+ " and CollectionAmount<="+querry.eskje+")";
            }
            string sql = @"select * from vw_skxx where (bmdm in " + querry.DepartID + ")" + str;
            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            //return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.PageSize, querry.Current);
            return await new RepositoryFactory().BaseRepository().FindList(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);
        }

        public static async Task<(IEnumerable<dynamic>, int)> Getskht(HT_SKHTGLQuerry querry)
        {
            string str = " and 1=1 and htzt='正常' and htje>isnull(zfje,0) and zt='3' and 1=1 ";
            if (!string.IsNullOrEmpty(querry.htbh) && querry.htbh != "string")
            {
                str += "and htbh like '%" + querry.htbh + "%'";
            }
            if (!string.IsNullOrEmpty(querry.htmc) && querry.htmc != "string")
            {
                str += " and htmc like '%" + querry.htmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.bmdm) && querry.bmdm != "string")
            {
                str += " and bmdm='" + querry.bmdm + "'";
            }
            if (!string.IsNullOrEmpty(querry.htlx) && querry.htlx != "string")
            {
                str += " and htlx='" + querry.htlx + "'";
            }
            if (!string.IsNullOrEmpty(querry.zt) && querry.zt != "string")
            {
                str += " and zt='" + querry.zt + "'";
            }
            if (!string.IsNullOrEmpty(querry.sfyskjh) && querry.sfyskjh != "string")
            {
                str += " and sfyskjh='" + querry.sfyskjh + "'";
            }
            if (!string.IsNullOrEmpty(querry.jfmc) && querry.jfmc != "string")
            {
                str += " and jfmc like '%" + querry.jfmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.htzt) && querry.htzt != "string")
            {
                str += " and htzt = '" + querry.htzt + "'";
            }
            if (querry.sqksrq != null && querry.sqjsrq != null)
            {
                if (querry.sqjsrq > querry.sqksrq)
                {
                    DateTime sqjsrq = Convert.ToDateTime(querry.sqjsrq);
                    string jsrq = sqjsrq.ToString("yyyyMMdd");
                    DateTime sqksrq = Convert.ToDateTime(querry.sqksrq);
                    string ksrq = sqksrq.ToString("yyyyMMdd");
                    str += " and (sqrq>='" + ksrq + "' and sqrq<='" + jsrq + "')";
                }
            }

            string sql = @"select * from vw_ht_skhtgl where (bmdm in " + querry.DepartID + " or htbh in (select distinct htbh from HT_htzxbm where deptid in " + querry.DepartID + "))" + str;
            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            // return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.PageSize, querry.Current);
            return await new RepositoryFactory().BaseRepository().FindList(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);

        }
        public static async Task<DataTable> getContractPlanx(string htbh, string listid)
        {
            if (string.IsNullOrEmpty(listid))
            {
                string sql = @"select a.*,isnull(kpje, 0) as kpje,jhskje - isnull(kpje, 0) as wkpje,skje,(select max(collectionTime) from vw_ht_skxx d where a.htbh=d.projectCode and a.listid=d.planid) as skrq from ht_skjh a 
left join (select distinct projectCode,planid,isnull(sum(payAmount), 0) as kpje from vw_ht_skxx where collectiontype='已开票' group by projectCode,planid) b 
on a.HTBH = b.projectCode and a.ListID = b.planid
left join (select distinct projectCode,planid,isnull(sum(CollectionAmount), 0) as skje from vw_ht_skxx where collectiontype='已对账' group by projectCode,planid) c 
on a.HTBH = c.projectCode and a.ListID = c.planid
                            where a.jhskje > isnull(skje, 0) and (a.htbh='" + htbh + "' or a.htbh=(select top 1 xmbh from vw_ht_skhtgl where htbh='"+htbh+"'))";
                return await new RepositoryFactory().BaseRepository().FindTable(sql, null);
            }
            else
            {
                string sql = @"select a.*,isnull(kpje, 0) as kpje,jhskje - isnull(kpje, 0) as wkpje,skje,(select max(collectionTime) from vw_ht_skxx d where a.htbh=d.projectCode and a.listid=d.planid) from ht_skjh a 
left join (select distinct projectCode,planid,isnull(sum(payAmount), 0) as kpje from vw_ht_skxx where collectiontype='已开票' group by projectCode,planid) b 
on a.HTBH = b.projectCode and a.ListID = b.planid
left join (select distinct projectCode,planid,isnull(sum(CollectionAmount), 0) as skje from vw_ht_skxx where collectiontype='已对账' group by projectCode,planid) c 
on a.HTBH = c.projectCode and a.ListID = c.planid
                            where a.listid='" + listid + "'";
                return await new RepositoryFactory().BaseRepository().FindTable(sql, null);
            }
        }
        public static async Task insertht_sk(HT_SKXX sk)
        {
            await new RepositoryFactory().BaseRepository().Insert(sk);
        }

        public static async Task deleteht_sk(string listid)
        {
            string sql = "delete from HT_SKXX where listid='" + listid + "'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }

        public static async Task updateht_sk(string zt, string listid)
        {
            string sql = "update HT_SKXX set zt='" + zt + "' where listid='" + listid + "'";
            if (zt == "3")
            {
                sql += "update HT_SKXX set collectiontype='已对账' where listid='" + listid + "'";
            }
            else
            {
                sql += "update HT_SKXX set collectiontype=NULL where listid='" + listid + "'";
            }
           
                sql += "update ht_zlht set zfje=(select sum(CollectionAmount) from ht_skxx where projectCode=(select projectCode from ht_skxx where listid='" + listid + "') and zt='3') " +
                        "where htbh=(select projectCode from ht_skxx where listid='" + listid + "')";
                sql += "update ht_tyskht set zfje=(select sum(CollectionAmount) from ht_skxx where projectCode=(select projectCode from ht_skxx where listid='" + listid + "') and zt='3') " +
                       "where htbh=(select projectCode from ht_skxx where listid='" + listid + "')";
            
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
        }


        public static async Task<IEnumerable<dynamic>> getht_skhtx(string id)
        {
            string sql = "select * from vw_ht_skhtgl where htbh=(select projectCode from HT_SKXX where listid='" + id + "')";
            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }

        public static async Task<IEnumerable<dynamic>> getht_skjhx(string id)
        {
            string sql = "select * from ht_skjh where listid=(select planid from HT_SKXX where listid='" + id + "')";
            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }

        public static async Task<IEnumerable<dynamic>> getht_sk(string id)
        {
            string sql = "select * from HT_SKXX where listid='" + id + "'";
            return await new RepositoryFactory().BaseRepository().FindList(sql, null);
        }
        #endregion
    }
}
